This problem is very similar to coins, it seems that the building of the man eight questions is not simple.
It would be nice to have a coins-style backpack.
2392
#include <iostream> #include <algorithm> #include <string.h> #include <stdlib.h> #include < Stdio.h> #define MAX (a) > (b)? ( A):(B) typedef long long ll;using namespace std;const int maxn=41000;struct p{int a,b,c;} P[maxn];bool cmp (const struct P &a,const struct p&b) {return a.b<b.b;} int Dp[maxn],use[maxn];int n,m,t;int K;int main () {while (~SCANF ("%d", &k)) {int maxh=0; for (int i=1;i<=k;i++) scanf ("%d%d%d", &p[i].a,&p[i].b,&p[i].c); Sort (p+1,p+1+k,cmp); Memset (Dp,-1,sizeof (DP)); dp[0]=0; for (int. i=1;i<=k;i++) {memset (use,0,sizeof (use)); for (int j=p[i].a;j<=p[i].b;j++) {if (Dp[j-p[i].a]!=-1 && use[j-p[i].a]<p[i].c &am p;& Dp[j-p[i].a]+p[i].a>dp[j]) {use[j]=use[j-p[i].a]+1; DP[J]=DP[J-P[I].A]+P[I].A; Maxh=max (maxh, Dp[j]); }}} cout<<maxh<<endl; } return 0;}
1276
#include <iostream> #include <algorithm> #include <string.h> #include <stdlib.h> #include < Stdio.h> #define MAX (a) > (b)? ( A):(B) typedef long long ll;using namespace std;const int maxn=10+1000;struct p{int a,c;} P[maxn];int dp[maxn*1000],use[maxn*1000];int n,m,t;int k;int main () {while (~SCANF ("%d", &k)) {int maxh=0; scanf ("%d", &n); for (int i=1;i<=n;i++) scanf ("%d%d", &p[i].c,&p[i].a); Memset (Dp,-1,sizeof (DP)); dp[0]=0; for (int. i=1;i<=n;i++) {memset (use,0,sizeof (use)); for (int j=p[i].a;j<=k;j++) {if (Dp[j-p[i].a]!=-1 && use[j-p[i].a]<p[i].c &&am P Dp[j-p[i].a]+p[i].a>dp[j]) {use[j]=use[j-p[i].a]+1; DP[J]=DP[J-P[I].A]+P[I].A; Maxh=max (Maxh,dp[j]); }}} cout<<maxh<<endl; } return 0;}
POJ 2392 (Space Elevator) 1276 (Cash machine) warp backpack