fork(2) download
  1. /*
  2. 1. Code not to get placed. Code because it's FUN.
  3. 2. Keep in mind, 1.1 seconds is really "slow",0.99 seconds is really fast :P.
  4. 3. Always remember, Hard Work beats talent when talent doesnt work hard ^_^.
  5. Name : Sarvagya Agarwal
  6. Institution: BITS Pilani,Rajasthan.
  7. Sophomore Year ^_^.
  8.  
  9. */
  10.  
  11. #include <bits/stdc++.h>
  12. using namespace std;
  13. #define is(X) cout<<#X<<" is "<<X<<endl
  14. const int MOD = 1e9+7;
  15. int n,filters[100004],dp[10][1050];
  16. int compute_ans(int i,int x)
  17. {
  18. if(i==n)
  19. {
  20. if(x==0)return 1;
  21. return 0;
  22. }
  23. //apply the ith filter
  24. int x_apply = filters[i]^x;
  25. int ans1,ans2;
  26. if(dp[i+1][x_apply]!=-1)ans1=dp[i+1][x_apply];
  27. else ans1=dp[i+1][x_apply]=compute_ans(i+1,x_apply)%MOD;
  28. if(dp[i+1][x]!=-1)ans2=dp[i+1][x];
  29. else ans2=dp[i+1][x]=compute_ans(i+1,x)%MOD;
  30. return dp[i][x]=(ans1+ans2)%MOD;
  31. }
  32. int main() {
  33. //fast;
  34. //freopen("input.txt","r",stdin);
  35. int t;
  36. scanf("%d",&t);//cin>>t;
  37. while(t--)
  38. {
  39. char s[10];
  40. scanf("%s",s);
  41. //is(s);
  42. for(int i=0;i<10;i++){s[i]=(s[i]=='w')?'1':'0';}
  43. //is(s);
  44. int photo = strtol(s,NULL,2);
  45. //is(photo);
  46. scanf("%d",&n);//cin>>n;
  47. for(int i=0;i<10;++i)for(int j=0;j<=n;j++)dp[i][j]=-1;
  48. for(int i=0;i<n;++i)
  49. {
  50. char x[10];
  51. scanf("%s",x);
  52. //is(x);
  53. for(int i=0;i<10;++i){x[i]=(x[i]=='+')?'1':'0';}
  54. //is(x);
  55. filters[i]=strtol(x,NULL,2);
  56. //is(filters[i]);
  57. }
  58. printf("%d\n",compute_ans(0,photo));//<<endl;
  59. }
  60. return 0;
  61. }
Success #stdin #stdout 0s 3896KB
stdin
1
wbwbwbwbwb
3
+-+-+-+-+-
+-+-------
----+-+-+-
stdout
1