poj 2392 Space Elevator
生活随笔
收集整理的這篇文章主要介紹了
poj 2392 Space Elevator
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意 :給定n種積木,每種積木都有一個高度hi,一個數量ci,還有一個限制條件,這個積木所在的位置不能高于ai,問能疊起的最大高度
// 這里有個問題需要注意 就是ai小的要先進行背包 不然 在 ai高度下 L1L2 和 L2L1是不一樣的
// 然后就是簡單的0-1背包了
#include <iostream> #include <algorithm> #include <queue> #include <math.h> #include <stdio.h> #include <string.h> using namespace std; #define MOD 1000000007 #define maxn 40010 int dp[maxn]; struct node{int h;int a;int c;bool operator <(const node &t) const{return a<t.a;} }ar[410]; int main() {int K;while(scanf("%d",&K)!=EOF){int i,j,k;for(i=0;i<K;i++)scanf("%d %d %d",&ar[i].h,&ar[i].a,&ar[i].c);sort(ar,ar+K);memset(dp,0,sizeof(dp));for(i=0;i<K;i++){for(k=1;k<=ar[i].c;k++)for(j=ar[i].a;j>=ar[i].h;j--)dp[j]=max(dp[j],dp[j-ar[i].h]+ar[i].h);}int ans=0;for(i=0;i<=ar[K-1].a;i++) ans=max(ans,dp[i]); // 開始直接輸出了dp[ar[K-1].a] ,WA 下面數據就說明了問題// 2
// 5 11 3
// 8 12 2
printf("%d\n",ans);}return 0; }
// 這里有個問題需要注意 就是ai小的要先進行背包 不然 在 ai高度下 L1L2 和 L2L1是不一樣的
// 然后就是簡單的0-1背包了
#include <iostream> #include <algorithm> #include <queue> #include <math.h> #include <stdio.h> #include <string.h> using namespace std; #define MOD 1000000007 #define maxn 40010 int dp[maxn]; struct node{int h;int a;int c;bool operator <(const node &t) const{return a<t.a;} }ar[410]; int main() {int K;while(scanf("%d",&K)!=EOF){int i,j,k;for(i=0;i<K;i++)scanf("%d %d %d",&ar[i].h,&ar[i].a,&ar[i].c);sort(ar,ar+K);memset(dp,0,sizeof(dp));for(i=0;i<K;i++){for(k=1;k<=ar[i].c;k++)for(j=ar[i].a;j>=ar[i].h;j--)dp[j]=max(dp[j],dp[j-ar[i].h]+ar[i].h);}int ans=0;for(i=0;i<=ar[K-1].a;i++) ans=max(ans,dp[i]); // 開始直接輸出了dp[ar[K-1].a] ,WA 下面數據就說明了問題// 2
// 5 11 3
// 8 12 2
printf("%d\n",ans);}return 0; }
?
轉載于:https://www.cnblogs.com/372465774y/p/3190748.html
總結
以上是生活随笔為你收集整理的poj 2392 Space Elevator的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WIN-8“内置管理员无法激活此应用”问
- 下一篇: Response 输出文件流过程中的等待