SRM 602 D1L1:TypoCoderDiv1,dp
2014-02-21 14:21
471 查看
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12924&rd=15820
由于X太大(1e9),所以使用 map 保存结果,dp[i][x] 表示参加i次比赛后 rating 为 x 时的最多颜色变化次数。
代码:
#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 **********************/
//map <long long, int> dp[55];
class TypoCoderDiv1 {
public:
int getmax(vector <int> D, int X) {
map <long long, int> dp[55];
int res = 0;
int n = D.size();
dp[0][X] = 0;
long long pre, cur;
for (int i = 1; i <= n; i++) {
for (auto it = dp[i-1].begin(); it != dp[i-1].end(); it++) {
pre = (*it).first; // 之前分数
if ( pre >= 2200 ) {
// must decrease
cur = max(0LL, pre - D[i-1]);
if (cur < 2200) {
dp[i][cur] = max( dp[i][cur], (*it).second + 1 );
}
} else {
// decrease
cur = max(0LL, pre - D[i-1]);
dp[i][cur] = max( dp[i][cur], (*it).second );
// increase
cur = pre + D[i-1];
dp[i][cur] = max(dp[i][cur], (*it).second + ( cur >= 2200 ? 1 : 0 ) );
}
}
}
for (auto it = dp
.begin(); it != dp
.end(); it++) {
res = max( res, (*it).second );
}
return res;
}
};
/************** Program End ************************/
由于X太大(1e9),所以使用 map 保存结果,dp[i][x] 表示参加i次比赛后 rating 为 x 时的最多颜色变化次数。
代码:
#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 **********************/
//map <long long, int> dp[55];
class TypoCoderDiv1 {
public:
int getmax(vector <int> D, int X) {
map <long long, int> dp[55];
int res = 0;
int n = D.size();
dp[0][X] = 0;
long long pre, cur;
for (int i = 1; i <= n; i++) {
for (auto it = dp[i-1].begin(); it != dp[i-1].end(); it++) {
pre = (*it).first; // 之前分数
if ( pre >= 2200 ) {
// must decrease
cur = max(0LL, pre - D[i-1]);
if (cur < 2200) {
dp[i][cur] = max( dp[i][cur], (*it).second + 1 );
}
} else {
// decrease
cur = max(0LL, pre - D[i-1]);
dp[i][cur] = max( dp[i][cur], (*it).second );
// increase
cur = pre + D[i-1];
dp[i][cur] = max(dp[i][cur], (*it).second + ( cur >= 2200 ? 1 : 0 ) );
}
}
}
for (auto it = dp
.begin(); it != dp
.end(); it++) {
res = max( res, (*it).second );
}
return res;
}
};
/************** Program End ************************/
相关文章推荐
- SRM 602 D2L3:BlackBoxDiv2,dp
- SRM 626 D1L1: FixedDiceGameDiv1,贝叶斯公式,dp
- TopCoder SRM 653 Div2 Problem 500 - RockPaperScissorsMagicEasy (DP)
- Topcoder SRM 663 Div2 Hard: CheeseRolling(状压DP)
- [DP] SRM 452 Div1 Hard IncreasingNumber
- SRM 719 div1 Medium (树形dp)
- [DP][拉格朗日插值][生成函数] SRM 629 Div1 Hard CandyDrawing
- [DP] Topcoder SRM 552 DIV1 Hard. HolyNumbers
- SRM 508 DIV1 500pt(DP)
- [DP 博弈] Topcoder SRM579 Div1. RockPaperScissors
- srm 653 div2 1000(dp)
- srm 654 div2 1000 (DP,最大连续和拓展, 有亮点)
- TopCoder SRM 602 Div1 第1题
- SRM 511 DIV1 500pt(DP)
- [期望DP] SRM 579 Div1 Hard RockPaperScissors
- [容斥 DP] Topcoder SRM 498 DIV1 Hard. FoxJumping
- Topcoder SRM 144 Div1 550(数学和dp问题求方案数,很有意思)
- DP SRM 661 Div2 Hard: ColorfulLineGraphsDiv2
- [树形DP] SRM 598 Div1 Hard TPS
- srm 301 div2 1000 (经典dp, 括号匹配)