牛客-Corn Fields
作者:互联网
题目传送门
sol:状压和动规,把每一行的m个01压缩成一个int
- 状压dp
#include "bits/stdc++.h" using namespace std; const int MAXN = 15; const int MOD = 1e8; int n, m; bool mp[MAXN][MAXN]; vector<int> num[MAXN], dp[MAXN]; void dfs(int i, int j, int k) { if (j > m) { num[i].push_back(k); dp[i].push_back(0); return; } dfs(i, j + 1, k << 1); if ((k & 1) == 0 && mp[i][j + 1] == 1) dfs(i, j + 1, k << 1 | 1); } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) scanf("%d", &mp[i][j]); dfs(i, 0, 0); } for (int j = 0; j < dp[1].size(); j++) dp[1][j] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j < dp[i].size(); j++) { for (int k = 0; k < dp[i - 1].size(); k++) { if ((num[i][j] & num[i - 1][k]) == 0) { dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD; } } } } int ans = 0; for (int j = 0; j < dp[n].size(); j++) ans = (ans + dp[n][j]) % MOD; printf("%d\n", ans); return 0; }
标签:int,Fields,Corn,状压,dfs,牛客,num,MAXN,dp 来源: https://www.cnblogs.com/Angel-Demon/p/11109628.html