SRM 602 D1L1:TypoCoderDiv1,dp
来源:互联网 发布:数据精灵9.8.2注册机 编辑:程序博客网 时间:2024/05/16 22:38
题目: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 decreasecur = max(0LL, pre - D[i-1]);if (cur < 2200) {dp[i][cur] = max( dp[i][cur], (*it).second + 1 );}} else {// decreasecur = max(0LL, pre - D[i-1]);dp[i][cur] = max( dp[i][cur], (*it).second );// increasecur = 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 ************************/
1 0
- SRM 602 D1L1:TypoCoderDiv1,dp
- SRM 626 D1L1: FixedDiceGameDiv1,贝叶斯公式,dp
- SRM 599 D1L1:BigFatInteger,math
- SRM 622 D1L1: BuildingRoutes,shortest path
- SRM 602 D2L3:BlackBoxDiv2,dp
- SRM 440 WickedTeacher (DP)
- srm 711 DerangementsDiv2(dp)
- SRM 599 D2L3: SimilarNames2,dp
- SRM 609 D2L3: VocaloidsAndSongs,dp
- SRM 604 D2L3:FoxConnection2,dp
- SRM 591 D2L3:YetAnotherTwoTeamsProblem,dp
- SRM 610 D2L3:MiningGoldEasy,dp
- SRM 574 D1L2:PolygonTraversal,dp
- SRM 612 D2L3:PowersOfTwo,dp
- SRM 615 D2L3:MergeStrings,dp
- SRM 615 D1L3: AlternativePiles, dp
- SRM 620 D2L3: RandomGraph, dp
- SRM 649 div2 500(dp)
- 自定义扩展jquery的ajax方法添加maskLoader
- C语言中预定义符 __FILE__, __LINE__, __FUNCTION__, __DATE__, __TIME__ 的使用演示
- UILabel使用技巧
- Hibernate -- 操作持久化对象
- IOS开发笔记
- SRM 602 D1L1:TypoCoderDiv1,dp
- jboss6 部署优化
- 关于Java虚拟机中的字节码指令javap
- 解决RedHat操作系统终端显示出现乱码的问题
- http协议学习系列
- codeforces 394A Counting Sticks(题目虽简单,但是考虑的情况多,需仔细)
- 虚拟机里的CentOS 6直接克隆或拷贝后无法识别eth0
- oracle11g rac 实例1不能启动 ORA-01078
- tomcat下Gzip压缩