SRM 551 div2
2012-08-12 16:30
369 查看
错过了。。。当练习做的。
250pt 略
500pt
怎么开始就没敢写暴力呢。。。。看别人的思路,挺巧妙的。Orz
950pt (对我来说是好题。。。)
挺好的dp。可是偶不会。。。根本不敢写。一个五维的状态 dp[A的个数][B的个数][C的个数][左端点(AorBorC)][右端点(AorBorC)] ;
然后一个很巧妙的记忆化搜索。
solve(pos, A, B, C, head, tail) //表示用掉pos个字符后,A的当前个数,B的当前个数,C的当前个数,串头的值,串尾的值。
250pt 略
500pt
怎么开始就没敢写暴力呢。。。。看别人的思路,挺巧妙的。Orz
class ColorfulChocolates { public: int maximumSpread(string c, int m) { int l = c.length(), i, j, num, cnt; int s[3000]; int sum, ans = 0, res; REP(i, l) { num = 0; cnt = 0; for(j = i - 1; j >= 0; --j) { if(c[i] == c[j]) s[cnt++] = num; else num++; } num = 0; for(j = i + 1; j < l; ++j) { if(c[i] == c[j]) s[cnt++] = num; else num++; } sort(s, s + cnt); sum = 0; res = 1; for(j = 0; j < cnt; ++j) { if(sum + s[j] > m) break; sum += s[j]; res++; } ans = max(ans, res); } return ans; } };
950pt (对我来说是好题。。。)
挺好的dp。可是偶不会。。。根本不敢写。一个五维的状态 dp[A的个数][B的个数][C的个数][左端点(AorBorC)][右端点(AorBorC)] ;
然后一个很巧妙的记忆化搜索。
solve(pos, A, B, C, head, tail) //表示用掉pos个字符后,A的当前个数,B的当前个数,C的当前个数,串头的值,串尾的值。
class ColorfulCupcakesDivTwo { public: LL dp [3][3]; int n; LL dfs(int pos, int a, int b, int c, int f, int l) { if(a < 0 || b < 0 || c < 0) return 0; if(pos == n) return f != l; if(dp[a][b][c][f][l] != -1) return dp[a][b][c][f][l]; LL res = 0; if(l == 0) { res = (res + dfs(pos + 1, a, b-1, c, 1, f))%mod; res = (res + dfs(pos + 1, a, b, c-1, 2, f))%mod; } if(l == 1) { res = (res + dfs(pos + 1, a-1, b, c, 0, f))%mod; res = (res + dfs(pos + 1, a, b, c-1, 2, f))%mod; } if(l == 2) { res = (res + dfs(pos + 1, a-1, b, c, 0, f))%mod; res = (res + dfs(pos + 1, a, b-1, c, 1, f))%mod; } return dp[a][b][c][f][l] = res; } int countArrangements(string c) { int i, a[4] = {0}; n = c.size(); REP(i, n) a[c[i]-'A']++; int ans = 0; CL(dp, 0XFF); ans = (ans + dfs(1, a[0] - 1, a[1], a[2], 0, 0))%mod; ans = (ans + dfs(1, a[0], a[1] - 1, a[2], 1, 1))%mod; ans = (ans + dfs(1, a[0], a[1], a[2] - 1, 2, 2))%mod; return ans; } };
相关文章推荐
- SRM 551 div2 950(DP, 环形+优化)
- [矩阵树定理 容斥 meet in middle] Topcoder SRM 551 DIV1 Hard. SweetFruits
- 【TopCoder SRM 551 Div2】Solutions
- [meet in middle 矩阵树定理 容斥原理] SRM 551 div1 SweetFruits
- TC SRM 551 div2 题解
- SRM 551 Div1
- SRM 551 DIV2
- SRM 604 DIV2 250
- Topcoder SRM 636 div2 1000
- Topcoder SRM 152 Div2 1000(状态压缩呀)
- srm 565 div2
- topcoder-srm144-div
- 博弈论重要算法:Sprague-Grundy 定理 (SRM 561 Div1 550)
- SRM 608 div2 500 MysticAndCandiesEasy
- SRM 638 Div2
- SRM 606 DIV1 450
- topcoder srm 610 div2 250
- topcoder srm 495 div1
- SRM 502 DIV1 500pt(DP)
- SRM 573 div2