首页 > 其他 > 详细

SRM 602 D1L1:TypoCoderDiv1,dp

时间:2014-02-22 08:14:57      阅读:343      评论:0      收藏:0      [点我收藏+]

题目: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 ************************/


SRM 602 D1L1:TypoCoderDiv1,dp

原文:http://blog.csdn.net/xzz_hust/article/details/19618751

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!