iscsi

Codechef Robot Movings

Dec 2nd, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. using namespace std;
  14. typedef unsigned long long LL;
  15. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  16. #define FORD(k,a,b) for(int k(a-1); k >= (b); --k)
  17. #define REP(k,a) for(int k=0; k < (a); ++k)
  18. #define ABS(a) ((a)>0?(a):-(a))
  19. typedef pair<int,int> pii;
  20. #define x first
  21. #define y second
  22.  
  23. int main()
  24. {
  25. #ifdef HOME
  26.     freopen ("in.txt","r",stdin);
  27. //  freopen ("out.txt","w",stdout);
  28. #endif
  29.     const int mSize=5001;
  30.     const int mod=1e9+7;
  31.     typedef int (array5k_t)[mSize];
  32.  
  33.     array5k_t* comb = new array5k_t[mSize];
  34.  
  35.     REP(i,mSize)
  36.         comb[i][0]=1,comb[i][i]=1;
  37.     FOR(i,1,mSize)
  38.     FOR(j,1,i)
  39.     {
  40.         comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
  41.         if(comb[i][j]>=mod)
  42.             comb[i][j]-=mod;
  43.     }
  44.     int N,K,K1,K2;
  45.     LL res=0;
  46.     while(true)
  47.     {
  48.         scanf("%d %d",&N,&K);
  49.         if(N==0 && K==0)
  50.             break;
  51.         if(N==1 || K>2*N-3)
  52.         {
  53.             //because k positive
  54.             printf("0\n");
  55.             continue;
  56.         }
  57.         --K;
  58.         K1=K/2;
  59.         K2=(K+1)/2;
  60.         res=2LL*comb[N-2][K1]*comb[N-2][K2];
  61.         res%=mod;
  62.         printf("%lld\n",res);
  63.     }
  64.     delete[] comb;
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment