2017 Baidu star qualifying round 1003: Dudu Xiong and evil devil (DP), 20171003

Source: Internet
Author: User

2017 Baidu star qualifying round 1003: Dudu Xiong and evil devil (DP), 20171003
Dudu bear and evil devil Accepts: 3021 Submissions: 18787 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) problem Description Dudu Xiong fought with the evil lord to save the lovely princess. There are n monsters under the Lord of evil, each of which has the life value of a [I] and the defensive power of B [I. Dudu Xiong has a total of m types of attacks. The I type of attacks consumes k [I] spar, resulting in point p [I] damage. Of course, if Dudu Xiong uses the I-th skill to hit the j-th monster, the life of the j-th monster will be reduced by p [I]-B [j], of course, if the damage is less than the defense, the attack will not work. If the life of a monster falls to 0 or below, the monster will be wiped out. Of course, each skill can be used for unlimited times. I would like to tell you how much space the Dudu bear carries at least to eliminate all monsters. Input this question contains several groups of test data. The first line has two integers, n and m, indicating that there are n monsters and m skills. In the next n rows, each line has two integers, a [I] and B [I], representing the life and defensive capabilities of monsters respectively. In the next m row, each row contains two integers, k [I] and p [I], indicating the number of consumed Spar and the damage value of the skill respectively. Data range: 1 <= n <= 100000 1 <= m <= 1000 1 <= a [I] <= 1000 0 <= B [I] <= 10 0 <= k [I] <= 100000 0 <= p [I] <= 1000Output for each group of test data, output the minimum amount of SPAR consumed. If you cannot beat all monsters, output-1 Sample InputCopy

1 23 57 106 81 23 510 78 6
Sample Output Copy
618
Http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php? Cid = 774 & pid = 1003 is a complete backpack. Each monster can be calculated separately. The answer is the total answer. Because the Protection Value of the monster is small, it can pre-process the minimum amount of SPAR consumed by monsters with different life and defense values under each set of skills. For each monster, take the answer directly, it is much faster than one request for every monster. Your own code and explanation: (it's ugly, and there's no one waiting for 2 * maxa ..) 1/* 2 ans [I] [j] [B] Monsters with defensive power of B 3 represent the first I skills, minimum spar 4 ans [I] [j] [B] = min {ans [I-1] [j-x * (p [I]-B)] + x * k [I]} 5 x indicates that x (0 <= x * (p [I]-B) <= j) is used for the I-th skill. 6 optimization: http://blog.csdn.net/wumuzi520/article/details/7014830 7 ans [I] [j] [B] = min (ans [I-1] [j] [B], ans [I] [j-(p [I]-B)] [B] + k [I] [j> = p [I]-B ]) 8 => ans [j] [B] = min (ans [j] [B], ans [j-(p [I]-B)] [B] + k [I] ** I from small to large 9 */10 # include <cstdio> 11 # include <cstring> 12 # include <algorithm> 13 using namespace std; 14 typedef long LL; 15 LL n, m; 16 LL maxb, maxp, bx, maxa; 17 LL a [100100], B [100100]; 18 LL ans [10001] [11]; 19 LL k [1010], p [1010], ans1; 20 int main () 21 {22 LL I, j, t, ze = (long) 0; 23 while (scanf ("% lld", & n, & m) = 2) 24 {25 maxb = 0; maxp = 0; maxa = 0; 26 for (I = 1; I <= n; I ++) 27 {28 scanf ("% lld ", & a [I], & B [I]); 29 maxb = max (maxb, B [I]); 30 maxa = max (maxa, a [I]); 31} 32 for (I = 1; I <= m; I ++) 33 {34 scanf ("% lld", & k [I], & p [I]); 35 maxp = max (maxp, p [I]); 36} 37 maxa = max (maxa, maxp ); 38/* 39 remove the above sentence, it will lead to the wrong result 44 */45 if (maxb> = maxp) for data similar to 40 1 141 45 1042 4164 32743) 46 {47 printf ("-1 \ n"); 48 continue; 49} 50 memset (ans, 0x3f, sizeof (ans); 51 memset (ans [0], 0, sizeof (ans [0]); 52 for (bx = 0; bx <= maxb; bx ++) 53 {54 for (I = 1; I <= m; I ++) 55 for (j = max (ze, p [I]-bx); j <= 2 * maxa; j ++) 56 // {57 // if (j> = p [I]-bx) 58 ans [j] [bx] = min (ans [j] [bx], ans [j-p [I] + bx] [bx] + k [I]); 59 //} 60 t = 0x3f3f3f3f; 61 for (j = 2 * maxa; j> = 0; j --) 62 {63 t = min (t, ans [j] [bx]); 64 ans [j] [bx] = min (ans [j] [bx], t); 65} 66} 67 ans1 = 0; 68 for (I = 1; I <= n; I ++) 69 ans1 + = ans [a [I] [B [I]; 70 printf ("% lld \ n", ans1 ); 71 72 73} 74 return 0; 75}View Code

 

2017 Baidu star qualifying round 1003: Dudu Xiong and evil devil (DP)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.