CodeForces 19B Checkout Assistant

B. Checkout Assistant
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its priceci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers tici(0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Examples
input
4
2 10
0 20
1 5
1 3
output
8
input
3
0 1
0 10
0 100
output
111
 
         
 
         
 
         
简单01背包,每个物品的付钱时间可以当作是买了这个物品还可以送你多少个物品。物品的数量相当于背包的体积,物品的价值相当于价值,问题就变成求背包体积大于等于n时,可以得到的最小价值
 
         
 
         
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>

using namespace std;
const long long int MAX=(long long int)1<<62;
long long int dp[2005];
long long int a[2005][2];
int n;
int main()
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
      scanf("%lld%lld",&a[i][0],&a[i][1]),a[i][0]++;
   for(int i=0;i<=n;i++)
	   dp[i]=MAX;
   dp[0]=0;
   for(int i=1;i<=n;i++)
   {
	   for(int j=n;j>=0;j--)
	   {
		   if(j>=a[i][0])
		   {
			   dp[j]=min(dp[j],dp[j-a[i][0]]+a[i][1]);
		   }
		   else
			   dp[j]=min(dp[j],a[i][1]);
	   }
   }
   printf("%lld\n",dp[n]);
   return 0;
}


 
         

转载于:https://www.cnblogs.com/dacc123/p/8228741.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值