SRM 602 D2L3:BlackBoxDiv2,dp
2014-02-21 16:44
239 查看
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12929&rd=15820
参考:http://apps.topcoder.com/wiki/display/tc/SRM+602
需要仔细分析,要注意base case的判断,还要注意不要漏了repaint的情况。
代码:
参考:http://apps.topcoder.com/wiki/display/tc/SRM+602
需要仔细分析,要注意base case的判断,还要注意不要漏了repaint的情况。
代码:
#include <algorithm> #include <functional> #include <numeric> #include <utility> #include <iostream> #include <sstream> #include <iomanip> #include <bitset> #include <string> #include <vector> #include <stack> #include <deque> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <cstring> #include <ctime> #include <climits> using namespace std; #define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC) typedef pair<int, int> pii; typedef long long llong; typedef pair<llong, llong> pll; #define mkp make_pair /*************** Program Begin **********************/ const int MOD = 1e9 + 7; long long dp[55][55]; long long C[55][55]; class BlackBoxDiv2 { public: int w, h; void calc() { C[0][0] = 1; for (int i = 1; i <= 50; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) { C[i][j] = C[i-1][j] + C[i-1][j-1]; C[i][j] %= MOD; } } } long long rec(int x, int y) { if (0 == x) { // base case if (0 == y) { return 1; } else { return 0; } } long long & res = dp[x][y]; if (res != -1) { return res; } res = 0; for (int s = 0; s <= y; s++) { for (int r = 0; r <= h - y; r++) { if (s + r < 1) { continue; } long long t = C[y][s] * C[h - y][r] % MOD; res += ( t * rec(x - 1, y - s) ) % MOD; res %= MOD; } } return res; } int count(string front, string side) { this->w = 0; this->h = 0; for (int i = 0; i < front.size(); i++) { w += ( front[i] == 'B' ? 1 : 0 ); } for (int i = 0; i < side.size(); i++) { h += ( side[i] == 'B' ? 1 : 0 ); } calc(); memset(dp, -1, sizeof(dp)); return rec(w, h); } }; /************** Program End ************************/
相关文章推荐
- SRM 602 D1L1:TypoCoderDiv1,dp
- srm 655 div2 1000(DP进阶,枚举状态)
- SRM 604 D2L3:FoxConnection2,dp
- TopCoder SRM 666 Div2 Problem 999 - WalkOverATreeDiv2 (树形DP)
- TopCoder SRM 653 Div2 Problem 500 - RockPaperScissorsMagicEasy (DP)
- [补集转换 DP] Topcoder SRM 509 DIV1 Hard. NumberLabyrinthDiv1
- TopCoder SRM 602 Div1 第1题
- Topcoder SRM 663 Div2 Hard: CheeseRolling(状压DP)
- SRM 620 D2L3: RandomGraph, dp
- srm 556 div1 500 LeftRightDigitsGame2(DP)
- SRM 620 D2L3: RandomGraph, dp
- SRM 508 DIV1 500pt(DP)
- srm 653 div2 1000(dp)
- srm 654 div2 1000 (DP,最大连续和拓展, 有亮点)
- SRM 511 DIV1 500pt(DP)
- Topcoder SRM 144 Div1 550(数学和dp问题求方案数,很有意思)
- SRM 610 D2L3:MiningGoldEasy,dp
- SRM 719 div1 Medium (树形dp)
- [DP][拉格朗日插值][生成函数] SRM 629 Div1 Hard CandyDrawing
- [DP] Topcoder SRM 552 DIV1 Hard. HolyNumbers