CodeForces 19 B.Checkout Assistant(01背包)

Description

n n 件物品,第i件物品收银时需耗费 ti t i 秒,价格为 pi p i ,在收银过程中每秒可以偷一件没有结账的物品,问最少需要多少钱可以带走这些物品

Input

第一行一整数 n n ,之后n行每行两个整数 ti,pi(1n2000,0ti2000,1pi109) 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 件物品,相当于用pi的价格拿走 ti+1 t i + 1 件物品,最后的目的是用最少的钱拿走 n n 件物品,把ti+1看作第 i i 件物品的体积,那么问题转化为n件物品,从中选出若干件使得其体积不小于 n n 且总价值最小,即为01背包问题

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;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值