=0;ans--)if(f[ans])break;printf("%d\n",m-ans);return 0;}/*in1:103485out1:1in2:90123745132847657out2。装箱问题。" />

装箱问题

#include using namespace std; int m,n,ans,w[31],f[20001]; int main() { scanf("%d%d",&m,&n); for(int i=1; i<=n; i++)scanf("%d",&w[i]); f[0]=1; for(int i=1; i<=n; i++) for(int j=m; j>=w[i]; j--) if(f[j-w[i]]) f[j]=1; for(ans=m; ans>=0; ans--) if(f[ans])break; printf("%d\n",m-ans); return 0; } /* in1: 10 3 4 8 5 out1: 1in2: 90 12 3 7 4 5 13 2 8 4 7 6 5 7 out2: 19in3: 100 16 16 3 5 16 16 16 16 16 16 16 16 16 16 16 16 16 out3: 1in4: 10 20 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 7 2 out4: 1in5: 20000 30 3536 4316 65 2717 6474 4602 689 13 1300 4147 6136 2587 3068 5811 4966 4810 52 5070 3757 1703 3497 3211 4719 1300 5005 6188 3055 169 3224 338 out5: 6 */


    推荐阅读