前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces 19B Checkout Assistant

CodeForces 19B Checkout Assistant

作者头像
ShenduCC
发布2018-04-26 16:00:38
8390
发布2018-04-26 16:00:38
举报
文章被收录于专栏:算法修养算法修养

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

代码语言:javascript
复制
4
2 10
0 20
1 5
1 3

output

代码语言:javascript
复制
8

input

代码语言:javascript
复制
3
0 1
0 10
0 100

output

代码语言:javascript
复制
111
代码语言:javascript
复制
代码语言:javascript
复制
代码语言:javascript
复制
代码语言:javascript
复制
简单01背包,每个物品的付钱时间可以当作是买了这个物品还可以送你多少个物品。物品的数量相当于背包的体积,物品的价值相当于价值,问题就变成求背包体积大于等于n时,可以得到的最小价值
代码语言:javascript
复制
代码语言:javascript
复制
#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;
}
代码语言:javascript
复制
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档