您的位置:首页 > 其它

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 ************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: