题目链接:点击打开链接
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 1152921504606846976 #define ll __int64 #define N 2005 ll n; ll dp[N<<1], c[N], t[N]; int main(){ ll i, j; while(cin>>n) { for(i=1;i<=n;i++) { cin>>t[i]>>c[i]; t[i]++; dp[i] = inf; } ll sum = inf; for(i=1;i<=n;i++) { for(j=n;j>=0;j--) if(dp[j] != inf || !j) { if(j+t[i]<n) dp[j+t[i]] = min(dp[j + t[i]], dp[j]+c[i]); else sum = min(sum, dp[j]+c[i]); } } cout<<sum<<endl; } return 0; }
CodeForces 19B Checkout Assistant dp,布布扣,bubuko.com
CodeForces 19B Checkout Assistant dp
原文地址:http://blog.csdn.net/qq574857122/article/details/35987303