Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Created January 26, 2022 10:21
Show Gist options
  • Select an option

  • Save hjroh0315/17e92d8522924cb8fa457ab77a3a21bc to your computer and use it in GitHub Desktop.

Select an option

Save hjroh0315/17e92d8522924cb8fa457ab77a3a21bc to your computer and use it in GitHub Desktop.
이거 맞나????????
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
const ll mod=10007;
ll mod_pow(int a,int n,int p)
{
ll ret=1;
ll A=a;
while(n)
{
if (n & 1)
ret=(ret*A)%p;
A=(A*A)%p;
n>>=1;
}
return ret;
}
ll factorial[mod];
void init(ll p)
{
factorial[0] = 1;
for(int i = 1;i <= p;i++)
factorial[i] = factorial[i-1]*i%p;
}
ll C(ll a,ll k,ll p)
{
ll re = 1;
while(a && k)
{
ll aa = a%p;ll bb = k%p;
if(aa < bb) return 0;
re = re*factorial[aa]*mod_pow(factorial[bb]*factorial[aa-bb]%p,p-2,p)%p;
a /= p;
k /= p;
}
return re;
}
int n,k;
vector<int> res;
int t;
ll count(int curr, int idx, int p)
{
if(idx==k-1&&res[idx]==curr)return 1;
if(curr==res[idx])
{
return count(curr+1,idx+1,p)%p;
}
else
{
return (C(n-curr+1,k-idx-1,p)+count(curr+1,idx,p))%p;
}
}
int main()
{
init(mod);
cin>>n>>k;
res.resize(k);
for(int&i:res)cin>>i;
cout<<count(1,0,mod);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment