题意:https://www.nitacm.com/problem_show.php?pid=1378

如题。

思路:

从第一行for到最后一行,枚举每一行的所有状态,进行转移,注意答案是dp【最后一行】【0】,因为最后一行是唯一确定的。

https://blog.csdn.net/Tc_To_Top/article/details/43891119

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr
 13 #include <string>
 14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 23 //******************
 24 int abss(int a);
 25 int lowbit(int n);
 26 int Del_bit_1(int n);
 27 int maxx(int a,int b);
 28 int minn(int a,int b);
 29 double fabss(double a);
 30 void swapp(int &a,int &b);
 31 clock_t __STRAT,__END;
 32 double __TOTALTIME;
 33 void _MS(){__STRAT=clock();}
 34 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
 35 //***********************
 36 #define rint register int
 37 #define fo(a,b,c) for(rint a=b;a<=c;++a)
 38 #define fr(a,b,c) for(rint a=b;a>=c;--a)
 39 #define mem(a,b) memset(a,b,sizeof(a))
 40 #define pr printf
 41 #define sc scanf
 42 #define ls rt<<1
 43 #define rs rt<<1|1
 44 typedef long long ll;
 45 const double E=2.718281828;
 46 const double PI=acos(-1.0);
 47 //const ll INF=(1LL<<60);
 48 const int inf=(1<<30);
 49 const double ESP=1e-9;
 50 const int mod=(int)1e9+7;
 51 const int N=(int)1e5+10;
 52
 53 ll dp[15][N];
 54 bool ok(int x,int l)
 55 {
 56     bool f=1;
 57     int cnt=0;
 58     for(int i=0;i<=l-1;++i)
 59     {
 60         if((x>>i)&1)
 61         {
 62             if(cnt&1)
 63                 return 0;
 64         }
 65         else
 66             cnt++;
 67     }
 68     if(cnt&1)f=0;
 69     return f;
 70 }
 71
 72 int main()
 73 {
 74     int n,m;
 75     while(sc("%d%d",&n,&m),n||m)
 76     {
 77         if(n*m%2==1)
 78         {
 79             pr("0\n");
 80             continue;
 81         }
 82         int m_=m;
 83         m=1<<m;
 84         for(int i=0;i<=n;++i)
 85             for(int j=0;j<=m;++j)
 86                 dp[i][j]=0;
 87         dp[0][0]=1;
 88         for(int i=1;i<=n;++i)
 89             for(int j=0;j<m;++j)
 90                 for(int k=0;k<m;++k)
 91                     if((j&k)==0&&ok(j^k,m_))
 92                         dp[i][k]+=dp[i-1][j];
 93         pr("%lld\n",dp[n][0]);
 94     }
 95     return 0;
 96 }
 97
 98 /**************************************************************************************/
 99
100 int maxx(int a,int b)
101 {
102     return a>b?a:b;
103 }
104
105 void swapp(int &a,int &b)
106 {
107     a^=b^=a^=b;
108 }
109
110 int lowbit(int n)
111 {
112     return n&(-n);
113 }
114
115 int Del_bit_1(int n)
116 {
117     return n&(n-1);
118 }
119
120 int abss(int a)
121 {
122     return a>0?a:-a;
123 }
124
125 double fabss(double a)
126 {
127     return a>0?a:-a;
128 }
129
130 int minn(int a,int b)
131 {
132     return a<b?a:b;
133 }
02-12 05:13