
DP
_Yyg
这个作者很懒,什么都没留下…
展开
-
hdu 4001 To Miss Our Children Time (DP)
思路:转化为DAG上的动态规划,长方体的“可堆叠”关系是一个典型的二元关系,用图来建模。如果一个长方体X可以放在另外一个长方体Y的上面我们就从X到Y连一条边。这个有向图在缩点后是无环的。是一个DAG,求DAG上的最大高度即可。代码:#include#include#includeusing namespace std;const int MAXN = 1000+5;long long原创 2013-08-02 14:05:01 · 505 阅读 · 0 评论 -
hdu 4607 Park Visit (DFS)
#include#include#includeusing namespace std;const int maxn = 100005;const int inf = 0x3f3f3f3f;int t , n , m , a , b , e , k;int head[maxn] , dp[maxn] , dis[maxn] , vis[maxn];struct T{原创 2013-08-17 09:51:54 · 460 阅读 · 0 评论 -
hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (多重背包)
#include#include#includeusing namespace std;int dp[109];int cost[109];int value[109];int country[109];int volume;void ZeroOne(int cost,int value){ for(int i=volume;i>=cost;i--) d原创 2013-09-04 17:11:13 · 616 阅读 · 0 评论 -
hdu 1300 Pearls (DP 类似最长上升子序列)
#include#includeint a[105] , p[105] , n , dp[105] , sum[105];void f(){ for(int i = 1 ; i <= n ; i ++){ dp[i] = (sum[i] + 10) * p[i]; for(int j = 1 ; j <= i ; j ++){原创 2013-09-03 20:12:03 · 668 阅读 · 0 评论 -
hdu 1227 Fast Food(DP 类似最大m子段和)
#include#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int n , k;int dis[205] , cost[205][205] , dp[205][205];int main(){ int cases = 1; while(~scanf("%d%d"原创 2013-09-03 20:09:51 · 609 阅读 · 0 评论 -
hdu 1114 Piggy-Bank (完全背包)
#include#include#includeusing namespace std;const int maxn = 505;const int inf = 0x3f3f3f3f;int n;int w[maxn] , c[maxn] , E , F , V , dp[maxn * 10000];int main(){ int t; scanf("%d"原创 2013-09-03 20:06:49 · 593 阅读 · 0 评论 -
hdu 1024 Max Sum Plus Plus (最大m子段和)
#include#include#includeusing namespace std;const long long mod=1e9+7;const int MAXN = 1000005;int max(int a ,int b){ return a > b ? a : b;}int n;int num[1000005];int dp[2][MAXN];int原创 2013-08-29 10:42:38 · 547 阅读 · 0 评论 -
hdu 1025 Constructing Roads In JGShining's Kingdom (DP + 二分)
#include#includeint n , str[500004];int stack[500004];int top;const int inf = 0x3f3f3f3f;void push(int n){ stack[top] = n; top ++; return;}int pop(){ top --; return stack[原创 2013-08-29 10:30:39 · 475 阅读 · 0 评论 -
hdu 1078 FatMouse and Cheese (滑雪加强版DP)
#include#includeint n , k , ans;const int maxn = 105;int map[maxn][maxn];int dp[maxn][maxn];int dir[4][2] = {1 , 0 , -1 , 0 , 0 , 1 , 0 , -1};int f(int x , int y){ int tx , ty; int ret原创 2013-08-29 10:45:02 · 531 阅读 · 0 评论 -
hdu 1080 Human Gene Functions (DP + 最长公共子序列)
#include#include#includeusing namespace std;const int maxn = 105;const int inf = 0x3f3f3f3f;char s1[maxn] , s2[maxn];int dp[maxn][maxn] ,l1 , l2;int map[6][6] = {{inf , inf ,inf ,inf ,inf ,原创 2013-08-28 19:25:57 · 488 阅读 · 0 评论 -
hdu 1074 Doing Homework (状态压缩 + DP)
#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int n;struct T{ char sub[104]; int cost; int dead;}wk[20];struct T1{ char s[20]; int mcost; i原创 2013-08-28 19:22:48 · 520 阅读 · 0 评论 -
hdu 4649 Professor Tian (DP)
代码:#include#include//using namespace std;int num[205] , n;char op[205];double p[205];double dp[205][205];int cases = 1;int main(){ while(~scanf("%d" , &n)){ for(int i = 0 ; i原创 2013-08-07 11:03:22 · 489 阅读 · 0 评论 -
hdu 1520 Anniversary party (DP)
这个不能过,找不出错。。。有知道的告诉一下。。#pragma comment(linker, "/STACK:1024000000,1024000000")#include#include#include#include#includeusing namespace std;const int maxn = 6010;struct T{ int u; in原创 2013-08-05 19:32:08 · 425 阅读 · 0 评论 -
poj 3249 Test for Job (DP)
思路:DP,仍然是求DAG图上的最长路径,枚举每一个入度为0的点,算出它可以到达的最长路径并且记录最大值即可。代码:#include#include#includeusing namespace std;struct T{ int u; int v; int next;}edge[1000010];int val[100010] , head[10000原创 2013-08-02 16:56:25 · 444 阅读 · 0 评论 -
poj 1088 滑雪 (DP)
思路:简单DP代码:#include#includeint r , c;int h[105][105];int dp[105][105];int f(int i , int j){ int max = -1; if(dp[i][j] != -1) return dp[i][j]; if(h[i - 1][j] = 0){ if(max原创 2013-07-24 10:10:31 · 366 阅读 · 0 评论 -
hdu 1561 The more, The Better (树形DP)
最简单的树形dp#include#include#includeusing namespace std;int n , m , e , a , b , val[205];int head[205];int dp[205][205];struct T{ int u , v , next;}edge[41000];void addedge(int u , int原创 2013-09-26 17:22:16 · 423 阅读 · 0 评论