fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long int ll ;
  5.  
  6. int main() {
  7. int n=3;
  8. vector<int>a={1,2,1};
  9. vector<int>b={3,1,1};
  10. vector<vector<int>>dpa(n,vector<int>(2,0));
  11. vector<vector<int>>dpb(n,vector<int>(2,0));
  12. if(a[0]%2==0){
  13. dpa[0][0]=1;
  14. }
  15. else{
  16. dpa[0][1]=1;
  17. }
  18. if(b[0]%2==0){
  19. dpb[0][0]=1;
  20. }
  21. else{
  22. dpb[0][1]=1;
  23. }
  24.  
  25.  
  26. for(int i=1;i<n;i++){
  27. if(a[i]%2==0){
  28. dpa[i][0]=(dpa[i-1][0]+dpb[i-1][0]);
  29. dpa[i][1]=(dpa[i-1][1]+dpb[i-1][1]);
  30. }
  31. if(a[i]%2!=0){
  32. dpa[i][0]=(dpa[i-1][1]+dpb[i-1][1]);
  33. dpa[i][1]=(dpa[i-1][0]+dpb[i-1][0]);
  34. }
  35. if(b[i]%2==0){
  36. dpb[i][0]=(dpa[i-1][0]+dpb[i-1][0]);
  37. dpb[i][1]=(dpa[i-1][1]+dpb[i-1][1]);
  38. }
  39. if(b[i]%2!=0){
  40. dpb[i][0]=(dpa[i-1][1]+dpb[i-1][1]);
  41. dpb[i][1]=(dpa[i-1][0]+dpb[i-1][0]);
  42. }
  43. }
  44.  
  45. cout<<"odd "<<(dpa[n-1][1]+dpb[n-1][1])<<endl;
  46. cout<<"even "<<(dpa[n-1][0]+dpb[n-1][0])<<endl;
  47.  
  48. return 0 ;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
odd 4
even 4