背包的几个问题

include

include

include

include

include

include

include

include

using namespace std;

int v,n,ti[33];
int ans;
int f[33][20010];
int main()
{

cin>>v>>n;
for(int i=1;i<=n;i++)	cin>>ti[i];
for(int i=1;i<=n;i++){
	for(int j=v;j>=0;j--){
		f[i][j]=max(f[i][j],f[i-1][j]);
		if(j >= ti[i])
			f[i][j]=max(f[i][j],f[i-1][j-ti[i]]+ti[i]);
	}
}
ans=f[n][v];
ans=v-ans;
cout<<ans<<endl;


return 0;

}
/*
10 3
1
5
7
*/

上一篇:器件:施密特触发 buffer用于晶振整形


下一篇:[BZOJ] 1563: [NOI2009]诗人小G