CodeChef submission 136803 (C++ 4.3.2) plaintext list. Status: WA, problem SNCK03, contest SNACKDWN. By Daemons (Daemons), 2009-11-21 23:59:11.
#include <iostream> #include <cstring> #include <stdio.h> #include <math.h> using namespace std; typedef long long int64; #define MOD 1000000007 int64 fac[20001], inv[20001]; long long modPow(int a, int p) { if (p==0) return 1; if (p%2==0) { int64 x=modPow(a,p/2); return (x*x)%MOD; } else { return ((int64)a*modPow(a,p-1))%MOD; } } void calcFac() { fac[0]=1; inv[0]=1; fac[1]=1; inv[1]=1; for (long long i=2;i<=20000;i++) { fac[i]=(fac[i-1]*i)%MOD; inv[i]=modPow(fac[i],MOD-2); } } long long comb(int n, int r) { return (((fac[n]*inv[r])%MOD)*inv[n-r])%MOD; } int N,K; int k[20001]; long long f[32][20041]; int main() { calcFac(); /* int tests; scanf("%d",&tests); while (tests-->0) { scanf("%d %d",&N,&K); for (long long i=1;i<=K;i++) { scanf("%d",&k[i-1]); --k[i-1]; } memset(f,0,sizeof(f)); for (long long b=0;b<=N;b++) { f[K-1][0] = 1; //printf("%d %d = %d\n",1,b,f[1][b]); } for(int at=K-2;at>=0;--at) { for(int b=0;b<=N;++b) { int above = (N-1) - k[at] - b; long long ret = 0; const int len = k[at+1]-k[at]; if((at&1) == 0) { //increasing //where is the last number for(int end=len;end <= above;++end)//above-skip >= len;++skip) { ret += f[at+1][b+end-len]*comb(end-1,len-1); if(ret >= MOD) ret -= MOD; } } else { //decreasing for(int end=len;end <= b;++end)//above-skip >= len;++skip) { ret += f[at+1][b-end]*comb(end-1,len-1); if(ret >= MOD) ret -= MOD; } } f[at][b] = ret; } } //now we simulate for at==0 long long out = 0; //what's the first number, man? for(int i=0;i<N;++i) { out += f[0][i]; if(out >= MOD) out -= MOD; } printf("%lld\n",out); }*/ return 0; } /* 3 4 3 1 3 4 10 6 1 2 5 7 8 10 20000 22 1 3 6 10 14 17 19 21 23 29 30 31 40 50 55 57 60 100 202 245 300 20000 */
Comments

