标签:初始 pac int ons cst ongl cout 现在 clu
又是背包...(这题比黄还简单)
一维dp. \(i\) 表示现在拿了课题数, \(dp[i]\) 表示拿到n个课题的最小花费.将dp初始化大一点就行,记得开longlong
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstring>
using namespace std;
const long long MAXN = 2e2+5;
long long n,m;
long long min(long long a, long long b){return a<b? a : b;}
long long max(long long a, long long b){return a>b?a:b;}
long long dp[MAXN];
inline void update(long long x, long long y){
for (long long i=n;i>=0;i--)//裸的背包
for (long long j=i-1;j>=0;j--)
dp[i] = min(dp[i],dp[j]+x*pow(i-j,y));
}
int main(){
cin >> n >> m;
memset(dp,0x3f3f3f3f3f,sizeof(dp));//初始化大一点
dp[0] = 0;//拿0个课题
for (long long i=0;i<m;i++){
long long a,b; cin >> a >> b;
update(a,b);
}
cout << dp[n];
}
标签:初始 pac int ons cst ongl cout 现在 clu
原文地址:https://www.cnblogs.com/DannyXu/p/12536352.html