<span style="font-size:18px;">#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define INF 0x3fffffff typedef struct { int w,s; }N; N node[10000]; int dp[10000]; int cmp(N n1,N n2) { if(n1.s==n2.s) return n1.w<n2.w; return n1.s<n2.s; } int main() { int i,j,n=0,s,w; while(scanf("%d%d",&w,&s)!=EOF) { if(s>=w) node[++n].w=w; node[n].s=s; } sort(node+1,node+n,cmp); int ans=0; for(i=1;i<=n;i++) dp[i]=INF; for(i=1;i<=n;i++) for(j=n;j>=1;j--) { if(dp[j-1]+node[i].w<=node[i].s) dp[j]=min(dp[j],dp[j-1]+node[i].w); if(dp[j]<INF) ans=max(ans,j); } printf("%d\n",ans); return 0; }</span>
UVA 10154Weights and Measures --dp
原文地址:http://blog.csdn.net/acm_lkl/article/details/42973151