inflate.cpp
来自「背包类问题浅析和一些背包类问题的解答源程序。」· C++ 代码 · 共 24 行
CPP
24 行
/*
ID:zhjshar1
PROG:inflate
LANG:C++
*/
#include <fstream>
using namespace std;
ifstream in( "inflate.in" );
ofstream out( "inflate.out" );
int main(){
const int MAXN = 10010;
int money, totobj, f[MAXN]={0}, value, price, i, j, tem;
in >>money >>totobj;
for( i=0; i<totobj; ++i ){
in >>value >>price;
for( j=price; j<=money; ++j )
if( (tem=f[j-price]+value) > f[j] ) f[j] = tem;
}
out <<f[money] <<endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?