SRM 602 D1L1:TypoCoderDiv1,dp

题目: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[n].begin(); it != dp[n].end(); it++) {
			res = max( res, (*it).second );
		}

		return res;
	}
};

/************** Program End ************************/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值