2019ACM-ICPC沈阳网络赛-C-Dawn-K's water(完全背包模板题)

Dawn-K‘s water 

1000ms

262144K

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

AC 代码:

 1 #include <bits/stdc++.h>
 2 #pragma GCC optimize(3)
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e6+7;
 6 const ll inf=0x3f3f3f3f3f;
 7 const int maxm=1e4;
 8 struct NODE
 9 {
10     ll wei;
11     ll val;
12 } node[maxn];
13 ll f[maxn];
14 template<class T>
15 inline void read(T &x)
16 {
17     T ans=0,f=1;
18     char ch=getchar();
19     while(ch>‘9‘||ch<‘0‘)
20     {
21         if(ch==‘-‘)f=-1;
22         ch=getchar();
23     }
24     while(ch<=‘9‘&&ch>=‘0‘)
25     {
26         ans=ans*10+(ch-‘0‘);
27         ch=getchar();
28     }
29     x=ans*f;
30 }
31 int main()
32 {
33     int n;
34     ll m;
35     while(~scanf("%d %lld",&n,&m))
36     {
37         for(register int i=1; i<=n; ++i)
38         {
39             read(node[i].val);
40             read(node[i].wei);
41         }
42         memset(f,inf,sizeof(f));
43         f[0]=0;
44         for(register int i=1; i<=n; ++i)
45         {
46             for(register int j=node[i].wei; j<=maxm; ++j)
47             {
48                 f[j]=min(f[j],f[j-node[i].wei]+node[i].val);
49             }
50         }
51         ll ansa=inf;
52         int ansb=0;
53         for(register int i=m; i<=maxm; ++i)
54         {
55             if(f[i]<ansa)
56             {
57                 ansa=f[i];
58                 ansb=i;
59             }
60             else if(f[i]==ansa&&ansb<i)
61             {
62                 ansb=i;
63             }
64         }
65         printf("%lld %d\n",ansa,ansb);
66     }
67     return 0;
68 }

2019ACM-ICPC沈阳网络赛-C-Dawn-K's water(完全背包模板题)

原文地址:https://www.cnblogs.com/CharlieWade/p/11519617.html

时间: 2024-10-07 16:55:44

2019ACM-ICPC沈阳网络赛-C-Dawn-K's water(完全背包模板题)的相关文章

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

2018 ICPC 徐州网络赛

2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution 将环变成链,设\(f[i][0\)~\(2]\),分别表示与第一个数相同,与第一个数不同,与第一个数相同,与第一个数的反相同.然后\(dp\)即可. 时间复杂度:\(O(n)\) B. BE, GE or NE solution 根据题目描述\(dp\)即可. 时间复杂度:\(O(nm)\) C.

2019 ICPC 南昌网络赛

2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 // 史上排名最高一次,开场不到两小时队友各A一题加水题共四题,排名瞬间升至三四十名 // 然后后三小时就自闭了,一题都没有突破...最后排名211 hhhh ? ? B. Fire-Fighting Hero 题意 队友做的,待补. ? AC代码 #include<cstdio> #includ

2019ACM-ICPC沈阳网络赛-K-Guanguan&#39;s Happy water(思维+暴力)

Guanguan's Happy water 4000ms 262144K Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerat

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

沈阳网络赛G-Spare Tire【容斥】

17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an?1??an?2?

2016 年沈阳网络赛---QSC and Master(区间DP)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Universi

2017 icpc 西安网络赛

F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关的公式: 然后写个快速幂预处理啥的,很快就解决了~ 1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL lon

2016沈阳网络赛 Barricade

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description The empire is under attack again. The general of empire is planning to defend his castle. The land can be seen as N towns and M roads, a