Description
n n 件物品,第件物品收银时需耗费 ti t i 秒,价格为 pi p i ,在收银过程中每秒可以偷一件没有结账的物品,问最少需要多少钱可以带走这些物品
Input
第一行一整数 n n ,之后行每行两个整数 ti,pi(1≤n≤2000,0≤ti≤2000,1≤pi≤109) t i , p i ( 1 ≤ n ≤ 2000 , 0 ≤ t i ≤ 2000 , 1 ≤ p i ≤ 10 9 )
Output
输出最少钱数
Sample Input
4
2 10
0 20
1 5
1 3
Sample Output
8
Solution
对于第 i i 件物品,相当于用的价格拿走 ti+1 t i + 1 件物品,最后的目的是用最少的钱拿走 n n 件物品,把看作第 i i 件物品的体积,那么问题转化为件物品,从中选出若干件使得其体积不小于 n n 且总价值最小,即为背包问题
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=2005;
int n,t[maxn],p[maxn];
ll dp[maxn];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%d",&t[i],&p[i]),t[i]++,dp[i]=1e18;
for(int i=1;i<=n;i++)
for(int j=n;j>=1;j--)
dp[j]=min(dp[j],dp[max(j-t[i],0)]+p[i]);
printf("%I64d\n",dp[n]);
return 0;
}