abinash_hstu

B - Halum Halum Permutation:

Jan 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. long long dp[1000007];
  4.  
  5. void pre()
  6. {
  7.     dp[1]=1;
  8.     dp[2]=1;
  9.     dp[3]=3;
  10.     for(int i=4; i<=1000002; i++){
  11.         dp[i] = i*dp[i-1] + i*dp[i-2] - dp[i-1] - 2*dp[i-2];
  12.         dp[i] = dp[i] % 1000000007;
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     //freopen("in.txt","r",stdin);
  19.     //freopen("out.txt","w",stdout);
  20.     pre();
  21.     int css,cs;
  22.     scanf("%d",&css);
  23.     for(cs=1; cs<=css; cs++){
  24.         int a;
  25.         scanf("%d",&a);
  26.         printf("Case %d: %lld\n",cs,dp[a]);
  27.     }
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment