Advertisement
a53

palid_fara_recursie

a53
Jul 27th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #define Kmax 10
  3. #define MOD 1000000007
  4. using namespace std;
  5. int c[2][Kmax];
  6.  
  7. void pdcomb(int n) /// folosesc doar doua linii (0 si 1)
  8. {
  9. for(int i=0;i<=Kmax;++i)
  10. c[0][i]=c[1][i]=0;
  11. c[0][0]=c[1][0]=1; /// coloana 0
  12. for(int i=1;i<=n;++i)
  13. {
  14. for(int j=1;j<=i;++j)
  15. c[1][j]=(c[0][j]+c[0][j-1]);
  16. for(int k=0;k<=i;++k)
  17. c[0][k]=c[1][k];
  18. }
  19. }
  20.  
  21. inline int P(int a,int n)
  22. {
  23. int p=1;
  24. while(n > 0)
  25. {
  26. if(n%2==1)
  27. p=1LL*p*a%MOD;
  28. n/=2;
  29. a=1LL*a*a%MOD;
  30. }
  31. return p;
  32. }
  33.  
  34. int main()
  35. {
  36. int n,m,k;
  37. unsigned int sol;
  38. cin>>n;
  39. while(n--)
  40. {
  41. cin>>m>>k;
  42. if(m%2)
  43. ++m;
  44. pdcomb(k);
  45. if(k==1)
  46. cout<<1<<'\n';
  47. else
  48. if(k==2)
  49. cout<<P(2,m-1)%MOD<<'\n';
  50. else
  51. {
  52. sol=0;
  53. for(int i=0;k>2*i;++i)
  54. sol+=(1ULL*c[1][i]*P(k-2*i,m))%MOD;
  55. cout<<(sol/P(2,k-1))%MOD<<'\n';
  56. }
  57. }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement