弄不出来
HJ16 购物单
#include<bits/stdc++.h> using namespace std; int main() { int n = 5,m =10; int w[6] = {0,20,10,10,30,40}; int v[6] = {0,5,2,1,5,7}; int b[n+1][m+1]; for(int i =1;i<=n;i++){ for(int j =1 ;j<=m;j++){ if(w[i]>j){ cout<<"e"<<endl; b[i][j] = b[i-1][j]; cout<<b[i][j]<<endl; } else{ b[i][j] = max(b[i-1][j],w[i]*v[i]+b[i-1][j-w[i]]); cout<<b[i][j]<<endl; } } } cout<<w[0]<<endl; cout<<w[1]<<endl; cout<<w[2]<<endl; cout<<v[1]<<endl; cout<<v[3]<<endl; cout<<b[n][m]<<endl; return 0; }