本文主要是介绍[HDU1693]Eat the Trees 插头DP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
bool x, y 打成int 搞了我好久QAQ
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#define SF scanf
#define PF printf
using namespace std;
typedef long long LL;
const int MAXN = 12;
const int MAXS = 1 << MAXN;
LL d[MAXN+10][MAXN+10][MAXS+10];
int M[MAXN+10][MAXN+10], n, m, S, SS;
int main() {int _T, kase = 0; SF("%d", &_T); while(_T--) {SF("%d%d", &n, &m);memset(d, 0, sizeof(d));for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)SF("%d", &M[i][j]);d[0][m][0] = 1;for(int i = 1; i <= n; i++) {for(int s = 0; s < (1<<m); s++) d[i][0][s<<1] = d[i-1][m][s];for(int j = 1; j <= m; j++) {for(int s = 0; s < (1<<m+1); s++) {int q = 1 << j, p = q >> 1;bool x = p & s, y = q & s;if(M[i][j]) {d[i][j][s] = d[i][j-1][s^p^q];if(x != y) d[i][j][s] += d[i][j-1][s];}else {if(!x && !y) d[i][j][s] = d[i][j-1][s];else d[i][j][s] = 0;}}}}PF("Case %d: There are %lld ways to eat the trees.\n", ++kase, d[n][m][0]);}return 0;
}
这篇关于[HDU1693]Eat the Trees 插头DP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!