2019ICPCshenyang网络赛(C. Dawn-K's water)

简介: 2019ICPCshenyang网络赛(C. Dawn-K's water)

题目:

Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package.

On this day, Dawn-K came to the supermarket to buy mineral water, he found that there are nntypes of mineral water, and he already knew the price pp and the weight cc (kg) of each type of mineral water. Now Dawn-K wants to know the least money aa he needs to buy no less than mm kilograms of mineral water and the actual weight bb of mineral water he will get. Please help him to calculate them.

Input

The input consists of multiple test cases, each test case starts with a number nn (1 \le n \le 10^31≤n≤103) – the number of types, and mm (1 \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 nn does not exceed 5e45e4.

Then followed n lines with each line two integers pp (1 \le p \le 10^91≤p≤109) – the price of this type, and cc (1 \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 aa and the weight of water Dawn-K will get bb. If this minimum cost corresponds different solution, output the maximum weight he can get.

(The answer aa is between 11 and 10^9109, and the answer bb is between 11 and 10^4104)

样例输入

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

样例输出

3 3
3 6

题意描述:这个题可以看成是一个完全背包的问题,就是要买满足至少m的水需要花费的最少钱是多少,其中n是水的种类,a[i]是水的价格,b[i]是以a[i]的价格买的水的重量。

程序代码:

#include<iostream>
#include<algorithm>
using namespace std;
long long mi=1e14;//表示样例所给的大小是10000
int a[1010],b[1010];
long long dp[50100];//给的样例是10^9,所以用long long
int main()
{
  int i,j,k,m,n,sum;
  long long x,y;
  while(scanf("%d%d",&n,&m)!=EOF)
  {
    sum=20010;
    for(i=0;i<n;i++)
      scanf("%d%d",&a[i],&b[i]);
    for(i=1;i<=sum;i++)
      dp[i]=mi;//定义最初的价格都是无穷大
    dp[0]=0;//买0需要花费0
    for(i=0;i<n;i++)
      for(j=b[i];j<=sum;j++)
      {
        dp[j]=min(dp[j],dp[j-b[i]]+a[i]);
      }
    x=dp[m];
    y=m;
    for(i=m+1;i<=sum;i++)//寻找在sum和m之间是否还有满足的其价格更低
    {
      if(dp[i]<=x)
      {
        x=dp[i];
        y=i;
      }
    } 
    printf("%lld %lld\n",x,y);  
  }
  return 0;
}
相关文章
|
9月前
|
机器学习/深度学习 人工智能 自然语言处理
智能语音识别技术在多语言环境中的应用与挑战####
随着全球化的不断推进,跨语言交流的需求日益增长,智能语音识别技术成为连接不同语言文化的桥梁。本文旨在探索该技术在多语言环境中的应用现状、面临的挑战及未来发展趋势,通过深入分析技术瓶颈与创新策略,为促进全球无障碍沟通提供新视角。 ####
|
6月前
|
SQL 人工智能 搜索推荐
通义灵码 Rules 来了:个性化代码生成,对抗模型幻觉
通义灵码又上新外挂啦,Project Rules来了。当模型生成代码不精准,试下通义灵码 Rules,对抗模型幻觉,硬控 AI 根据你的代码风格和偏好生成代码和回复。
1244 7
|
10月前
|
API 数据库
Abp源码分析之Abp最小系统
本文详细介绍了如何构建一个基于ABP框架的最小系统,包括创建API项目、配置模块、访问数据库等步骤。通过创建API项目、修改`Program.cs`和`BookAbpModule.cs`文件,以及添加模块和数据库访问功能,最终实现了基本的CRUD操作。文章还展示了如何使用Swagger生成API文档,并通过控制台输出验证模块的加载顺序。适合初学者快速上手ABP框架。
152 3
Abp源码分析之Abp最小系统
|
存储 Serverless API
Serverless 架构实现弹幕场景问题之在initializer方法中初始化数据库实例如何解决
Serverless 架构实现弹幕场景问题之在initializer方法中初始化数据库实例如何解决
109 0
|
JavaScript Java 关系型数据库
品牌银饰售卖|基于SSM+vue的品牌银饰售卖平台的设计与实现(源码+数据库+文档)
品牌银饰售卖|基于SSM+vue的品牌银饰售卖平台的设计与实现(源码+数据库+文档)
131 0
|
关系型数据库 MySQL 数据安全/隐私保护
【MySQL】补充和navicat的一些简单使用
【MySQL】补充和navicat的一些简单使用
103 0
|
存储 编译器 C++
C++ 基本的输入输出
C++ 基本的输入输出
|
SQL 关系型数据库 HIVE
Hive中的HQL是什么?请解释其语法和常用操作。
Hive中的HQL是什么?请解释其语法和常用操作。
179 0

热门文章

最新文章