随笔分类 -  DP

While hard,but beautiful!
摘要:题目:Y原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705分析:树形dp的思想,枚举中间点。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define maxn 10000510 #define LL __int6411 #pragma comment(linker, "/STACK:16777216")12 vectore[maxn];13 LL ans,sum 阅读全文
posted @ 2013-09-15 22:42 EtheGreat 阅读(179) 评论(0) 推荐(0)
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1300分析:dp,最长公共上升子列。对于两个序列num1[maxn],num2[maxn]:如果num1[i]==num2[j],dp[i][j]=max(dp[i][k])+1;(knum2[k]).否则dp[i][j]=dp[i-1][j]. 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1005 6 using namespace std; 7 int n1,n2,ans; 8 int num1[maxn],num2[maxn 阅读全文
posted @ 2013-09-02 17:42 EtheGreat 阅读(160) 评论(0) 推荐(0)
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1732分析:dp,n个相同物品放入m个相同的盒子(允许为空)的个数为dp[n][m]=dp[n][m-1]+dp[n-m][m];dp[n][m-1]表示有空盒的情况,dp[n-m][m]表示没有空盒的情况。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 101 7 #define mod 1000007 8 using namespace std; 9 int dp[maxn][maxn];10 void s 阅读全文
posted @ 2013-08-31 13:52 EtheGreat 阅读(132) 评论(0) 推荐(0)
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1404分析:定义dp[i][j]表示i位时最左边为j时的情况,那么dp[i][[j]可以由dp[i-1][k](k>=j)得到。Non-Decreasing Digits#include#include#include#include#define maxn 100005#define ll long longusing namespace std;ll dp[70][12];void solve(){ for(int i=0;i=0;j--) { dp[i][j]=sum+dp[i-1][j]; 阅读全文
posted @ 2013-08-01 21:59 EtheGreat 阅读(200) 评论(0) 推荐(0)
摘要:原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=min(i,dp[i-j*j]+1)(1#include#include#include#include#include#include#include#define ll long long#define maxn 60005using namespace std;int dp[maxn];void solve(){ memset(dp,0,sizeof(dp)); dp[0]=0;dp[1]... 阅读全文
posted @ 2013-07-31 23:35 EtheGreat 阅读(192) 评论(0) 推荐(0)
摘要:原题链接:http://acm.uestc.edu.cn/problem.php?pid=1369&cid=192分析:DP,dp[i][0]表示第i个人不是lover时的最小值,dp[i][1]表示是的情况.I'm Hungry 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define maxn 100005 8 using namespace std; 9 int num[maxn],dp[maxn][2];10 int main()11 {12 int T,n,cas=1;13 阅读全文
posted @ 2013-07-17 21:42 EtheGreat 阅读(198) 评论(0) 推荐(0)