标签:rip 现在 数据 遍历 开始 gets 二进制 desc 字符
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 32802 | Accepted: 12650 |
Description
Input
Output
Sample Input
5 4 PHPP PPHH PPPP PHPP PHHP
Sample Output
6
Source
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <cmath> 5 #include <cstring> 6 7 using namespace std; 8 typedef long long LL; 9 #define inf 0x3f3f3f3f 10 11 const int maxn = 105; 12 int n, m, mostm; 13 int dp[maxn][80][80], dixing[maxn]; 14 int cntone[80], S[80], cnt; 15 16 bool valid(int i, int x) 17 { 18 if (dixing[i] & x)return false; 19 else return true; 20 } 21 22 int get_one(int x) 23 { 24 int res = 0; 25 while (x) { 26 res += (x & 1); 27 x >>= 1; 28 } 29 return res; 30 } 31 32 bool ok(int x) 33 { 34 if (x & (x << 1))return false; 35 if (x & (x << 2)) return false; 36 return true; 37 } 38 39 void getS() 40 { 41 cnt = 0; 42 mostm = 1 << m; 43 for (int i = 0; i < mostm; i++) { 44 if (ok(i)) { 45 S[cnt] = i; 46 cntone[cnt] = get_one(i); 47 cnt++; 48 } 49 } 50 } 51 52 int main() 53 { 54 while (scanf("%d%d", &n, &m) != EOF) { 55 getS(); 56 memset(dixing, 0, sizeof(dixing)); 57 for (int i = 1; i <= n; i++) { 58 char tmp[20]; 59 scanf("%s", tmp); 60 //printf("%s", tmp + 1); 61 for (int j = 0; j < m; j++) { 62 //cout<<tmp[j]<<endl; 63 if (tmp[j] == ‘H‘) { 64 dixing[i] |= (1 << (m - 1 - j)); 65 } 66 } 67 } 68 69 memset(dp, -1, sizeof(dp)); 70 dp[0][0][0] = 0; 71 int ans = 0; 72 for (int j = 0; j < cnt; j++) { 73 if (valid(1, S[j])) { 74 dp[1][j][0] = cntone[j]; 75 ans = max(ans, dp[1][j][0]); 76 } 77 } 78 //cout<<1<<" "<<ans<<endl; 79 80 for (int i = 2; i <= n; i++) { 81 int tiaoshi = -1; 82 for (int j = 0; j < cnt; j++) { 83 if (valid(i, S[j])) { 84 for (int k = 0; k < cnt; k++) { 85 if (valid(i - 1, S[k]) && (S[j] & S[k]) == 0) { 86 int mmm = -1; 87 for (int l = 0; l < cnt; l++) { 88 if (valid(i - 2, S[l]) && dp[i - 1][k][l] != -1 && (S[j] & S[l]) == 0) { 89 mmm = max(mmm, dp[i - 1][k][l]); 90 } 91 } 92 //cout<<i - 1<<" "<<mmm<<endl; 93 dp[i][j][k] = max(dp[i][j][k], mmm + cntone[j]); 94 tiaoshi = max(tiaoshi, dp[i][j][k]); 95 if (i == n)ans = max(ans, dp[i][j][k]); 96 } 97 } 98 } 99 } 100 //cout<<i<<" "<<tiaoshi<<endl; 101 } 102 printf("%d\n", ans); 103 } 104 105 //return 0; 106 }
标签:rip 现在 数据 遍历 开始 gets 二进制 desc 字符
原文地址:https://www.cnblogs.com/wyboooo/p/9796829.html