usaco_inflate.cpp

来自「usaco自己做的1到5章的代码」· C++ 代码 · 共 29 行

CPP
29 行
字号
/*
ID: wangyuc2
PROG: inflate
LANG: C++
*/
#include <fstream>
#include <iostream>
#include <cmath>
#include <memory>
#include <iomanip>
#define cin fin
using namespace std;
ifstream fin("inflate.in");
ofstream fout("inflate.out");
long int bag[10005];
int m,n;
int main()
{  
    int i,j,k,points,time;
    cin>>m>>n;
    for(i=0;i<n;i++)
      { cin>>points>>time;
        for(j=time;j<=m;j++)
        if(bag[j-time]+points > bag[j]) bag[j]=bag[j-time]+points;
      }
    fout<<bag[m]<<endl;
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?