FZU 1502 Letter Deletion(DP)】的更多相关文章

Description You are given two words (each word consists of upper-case English letters). Try to delete some letters from each word so that the resulting words are equal. What is the maximum possible length of the resulting word? Input There will be no…
最长公共子序列. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue>…
FZU - 2204 简单环形dp 题目链接 n个有标号的球围成一个圈.每个球有两种颜色可以选择黑或白染色.问有多少种方案使得没有出现连续白球7个或连续黑球7个. 输入 第一行有多组数据.第一行T表示组数.(T <= 20) 每组包含n,表示球的个数.(1 <= n <= 100000) 输出 每组先输出 "Case #x: " (其中x为当前组数) 该行接下来输出方案数.方案数mod 2015. 样例 2 7 1 Case #1: 126 Case #2: 2 思路…
云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 思想是很好想的..唯一的难点大概是 c++里面没有同或这种东西 得自己写 而我又不怎么会位运算 问了蕾姐半天也没搞懂怎么用~这个取反符号 到最后怒而手写了函数 一开始想的是 init后 输入nm都可以秒出 但是在使用~的路途上 发现至少我的方法 做这个题 不能做到init后随便输入 因为 每行 都有…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1502 题目大意:找出总的满足条件的字符串数,num(a)=num(b)=num(c)且任何前缀均满足num(a)>=num(b)>=num(c) 解题思路:用dp[i][j][k]表示a取i个,b取j个,c取k个的状态下最多有多少种满足条件的情况,容易推得状态转移方程如下: dp[i][j][k]=dp[i-1][j][k](i>j时)+dp[i][j-1][k](j>k时)+dp[i…
Letter time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was n…
定义dp[t][x1][y1][x2][y2]为在t时刻,人走到x1,y1,影子走到x2,y2所获得最大价值 最终就是所有的dp[max][..][..][..][..]的最大值 然后递推也很自然,枚举人和影子的动向,唯一注意的是当走到一点时,只获得一次价值,要除以2 然后对于每一层时间,其实有效的很少,所以用bfs取有效点更新,这样可以减少一些时间复杂度,最终跑出来1593ms #include <stdio.h> #include <iostream> #include <…
题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=38054 题意:求区间[a,b]中包含'1'的个数. 分析:数位dp,dp[pos][sum]表示第pos位已包含sum个1时pos后面可以任意填(即!limit时)的状态. 数位dp学习资料: http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html kuangbin :http://www.cnb…
题意:给定一个图,X表示不能走,O表示必须要走,*表示可走可不走,问你多少种走的法,使得形成一个回路. 析: 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #inclu…
题目链接:http://codeforces.com/problemset/problem/180/C 题意: 给你一个字符串s,长度为n. 让你将这个字符串变成“前面一段都是大写字母,后面一段都是小写字母”的形式. (也可以全是大写或全是小写) 问你最少改动几个字符. 题解: 表示状态: dp[i][0/1] = min changes 表示考虑到第i个字符,s[i]改成了大写(1)或小写(0)时的最小代价 找出答案: ans = min(dp[n][0], dp[n][1]) 如何转移: d…