完全背包——洛谷 P1853 投资的最大效益

原题链接

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const ll N=15;
const ll U=1000;
const ll maxn=4e3+5;
ll s,n,d;
ll a[N],b[N];
ll dp[maxn];
int main(){
    scanf("%lld%lld%lld",&s,&n,&d);
    for(int i=1;i<=d;++i)
        scanf("%lld%lld",&a[i],&b[i]);
    for(ll i=1;i<=n;++i){
        memset(dp,0,sizeof(dp));
        for(ll j=1;j<=d;++j)
            for(ll k=a[j]/U;k<=s/U;k++)
                dp[k]=max(dp[k],dp[k-a[j]/U]+b[j]);
        s+=dp[s/U];
    }
    printf("%lld\n",s);
    return 0;
}
posted @ 2022-04-04 14:42  Ryomk  阅读(30)  评论(0编辑  收藏  举报