随笔分类 - 动态规划-dp
摘要:Codeforces Round #436 (Div. 2) 敲出一身冷汗。。。感觉自己宛如智障:( codeforces 864 A. Fair Game【水】 题意:已知n为偶数,有n张卡片,每张卡片上都写有一个数,两个人每人选一个数,每人可以拿的卡片必须写有是自己选的数,问能否选择两个数使得两
阅读全文
摘要:题目链接:hdu 6169 gems gems gems Now there are n gems, each of which has its own value. Alice and Bob play a game with these n gems. They place the gems i
阅读全文
摘要://yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想。 题目链接:codeforces 814 C. An impassioned circulation of affection 题意:给出字符串长度n (1 ≤ n ≤ 1 500),字符串s由小写字母组成,
阅读全文
摘要://yy:那天考完概率论,上网无聊搜个期望可加性就搜到这题,看到以后特别有亲和感,挺有意思的。 hdu5194 DZY Loves Balls 【概率论 or 搜索】 题意: 一个盒子里有n个黑球和m个白球【n,m≤12】。每次随机从盒子里取走一个球,取了n+m次后,刚好取完。现在用一种方法生成了一
阅读全文
摘要:题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数。 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]
阅读全文
摘要:题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L。 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文子串的个数,再用背包思想判断是否有解。 dp[i][j]:选取i个回文子串,长度之和是否为j 其中用
阅读全文
摘要:题目链接:51nod 1412 AVL树的种类 开始做的时候把深度开得过小了结果一直WA,是我天真了。。 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 using namespace
阅读全文
摘要:题目链接:51nod 1134 最长递增子序列 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N = 50001; 6 int a[N]; 7 int b
阅读全文
摘要:题目链接:51nod 1183 编辑距离 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N = 1001; 6 char a[N], b[N]; 7 in
阅读全文
摘要:题目链接:51nod 1158 全是1的最大子矩阵 题目分类是单调栈,我这里直接用与解最大子矩阵类似的办法水过了。。。 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 #define C
阅读全文
摘要:题目链接:51nod 1051 最大子矩阵和 实质是把最大子段和扩展到二维。读题注意m,n。。。 1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<algorithm> 5 #define CLR(a,b) me
阅读全文
摘要:51nod 1021 石子归并 题解:从i到j合并的最小值:dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + sum[j] - sum[i-1]); 最后dp[1][n]即为所求结果。 1 #include<cstdio> 2 #include<alg
阅读全文

浙公网安备 33010602011771号