题意(Codeforces-455A) 给你\(n\)个数,你每次可以选择删除去一个数\(x\)获得\(x\)分,但是所有为\(x+1\)和\(x-1\)的数都得删去.问最大获得分数. 分析 这是一条经典dp.阶段是很自然的:我从左往右依次选择到每种数(先预处理在桶内),然后两个决策:拿,还是不拿(拿一定拿光).拿,那么下一步就不能选择\(x+1\)了,直接选择\(x+2\):不拿,我可以选择\(x+1\).两种情况取最大. 于是有状态转移方程:\(dp[x]=max(dp[x-1], dp[x…
题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) i * cnt[i]); 只和x-1,x-2有关,和顺序无关,x-1不取,x-2取那么累加相同的值,ans = dp[mx] */ #include <cstdio> #include <algorithm> #include <cstring> #include <…
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; ll dp[MAXN][]; ll cnt[MAXN]; ll work(…
题意与分析 题意:给出\(n\)个字符串,可以反转任意串,反转每个串都有其对应的花费\(c_i\).经过操作后是否能满足字符串\(\forall i \in [1,n] \text{且} i \in R_+, str[i]\ge str[i-1]\),若能输出最小花费,否则输出-1. 分析:经过各种字符串dp血虐,应该会有个直觉:\(dp[i]\)表示前\(i\)个串的最小花费.但是好像不太够:没有保存反转.因此,在dp中,如果状态不够,那就加维度保存状态.这里就是:我们定义\(dp[i][0]…
题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2,...,K\),问现有多少条路径,使从根节点出发到某个结点所经过的边权重之和恰为n,且经过的边至少有一条权重不小于\(d\). 我们来考虑一下阶段:一层一层的走下去--这个是显然的.而状态是什么?影响我们答案(路径条数)的只有一个,权重的和,它是由我们底下的若干个孩子所走的权重和的情况的和构成的.从…
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A Description Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and d…
题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with…
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. 简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i). #include <bits/stdc++.h> using namespace std; typedef __int64 LL; ; LL a…
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game…