标签:clu put 之间 while space 分割 namespace ons idt
Input
Output
Sample Input
5 4 PHPP PPHH PPPP PHPP PHHP
Sample Output
6
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 typedef long long LL; 6 const int maxn = 1e6 + 10; 7 const int INF = 0x7fffffff; 8 const int mod = 100000000; 9 char tu[105][12]; 10 int sum[105], mp[105], dp[105][70][70], state[105]; 11 int n, m; 12 int cal(int x) { 13 int ret = 0; 14 while(x) ret += (x & 1), x >>= 1; 15 return ret; 16 } 17 int main() { 18 scanf("%d%d", &n, &m); 19 for (int i = 1 ; i <= n ; i++) { 20 scanf("%s", tu[i]); 21 for (int j = 0 ; j < strlen(tu[i]) ; j++) 22 if (tu[i][j] == ‘H‘) mp[i] |= (1 << j); 23 } 24 int tot = 0; 25 for (int i = 0 ; i < (1 << m) ; i++) { 26 if (!(i & (i <<1)) && !(i & (i << 2))) state[++tot] = i, sum[tot] = cal(i); 27 } 28 for (int i = 1 ; i <= tot ; i++) 29 if (!(state[i]&mp[1])) dp[1][1][i] = sum[i]; 30 for (int i = 1 ; i < n ; i++) { 31 for (int j = 1 ; j <= tot ; j++) { 32 for (int k = 1 ; k <= tot ; k++) { 33 if (!(state[j]&state[k]) && dp[i][j][k] ) { 34 for (int q = 1 ; q <= tot ; q++) { 35 if (!(state[q]&state[j]) && !(state[q]&state[k]) && !(state[q]&mp[i + 1])) 36 dp[i+1][k][q] = max(dp[i][j][k] + sum[q], dp[i+1][k][q]); 37 } 38 } 39 } 40 } 41 } 42 int ans = 0; 43 for (int i = 1 ; i <= tot ; i++) { 44 for (int j = 1 ; j <= tot ; j++) { 45 ans = max(ans, dp[n][i][j]); 46 } 47 } 48 printf("%d\n", ans); 49 return 0; 50 }
标签:clu put 之间 while space 分割 namespace ons idt
原文地址:https://www.cnblogs.com/qldabiaoge/p/9345726.html