The Preliminary Contest for ICPC Asia Shenyang 2019 C. Dawn-K's water

Input

The input consists of multiple test cases, each test case starts with a number nnn (1≤n≤1031 \le n \le 10^31≤n≤103) -- the number of types, and mmm (1≤m≤1041 \le m \le 10^41≤m≤104) -- the least kilograms of water he needs to buy. For each set of test cases, the sum of nnn does not exceed 5e45e45e4.

Then followed n lines with each line two integers ppp (1≤p≤1091 \le p \le 10^91≤p≤109) -- the price of this type, and ccc (1≤c≤1041 \le c \le 10^41≤c≤104) -- the weight of water this type contains.

Output

For each test case, you should output one line contains the minimum cost aaa and the weight of water Dawn-K will get bbb. If this minimum cost corresponds different solution, output the maximum weight he can get.

(The answer aaa is between 111 and 10910^9109, and the answer bbb is between 111 and 10410^4104)

样例输入

3 3
2 1
3 1
1 1
3 5
2 3
1 2
3 3

样例输出

3 3
3 6

题意:给你n种水,每种水有价值x,重量y,问买m千克的水至少要花多少钱

思路:完全背包改改就可以过了

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;

int dp[1050010];
int c[1050010],w[1050010];

int main()
{
    int m,v;
    while(scanf("%d%d",&m,&v)!=EOF)
    {
        int v1=v;
        for(int i=0; i<m; i++)
        {
            scanf("%d%d",&c[i],&w[i]);
        }
        v=1000;
        v*=11;
        memset(dp,INF,sizeof(dp));
        dp[0]=0;
        for(int i=0; i<m; i++)
            for(int j=w[i]; j<=v; j++)
                dp[j]=min(dp[j],dp[j-w[i]]+c[i]);
        int tempk=INF,tempg=0;
        for(int i=v1;i<=v;i++)
        {
            if(tempk>=dp[i])
            {
                tempk=dp[i];
                tempg=i;
            }
           
            //printf("dp[%d]=%d\n",i,dp[i]);
        }
        printf("%d %d\n",tempk,tempg);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值