[Boring test events] T5 best choice issue

But also a backpack ... (This question is also easier than yellow)

One-dimensional dp. \ (I \) denote the number of subjects took now, \ (dp [i] \) represents the minimum cost to get n number of topics. Dp initialize the bigger the line, remember to open 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];
}

Guess you like

Origin www.cnblogs.com/DannyXu/p/12536352.html