(Hdu step 4.2.7) Kill the Monster (there are n skills to find the minimum number of uses of the skill to kill monsters. When using a certain skill, if the monster's energy value is hp<=m, the damage is twice times the original value.

Source: Internet
Author: User



Topic:

Kill the Monster
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 133 Accepted Submission (s): 97
Problem Descriptionthere is a mountain near Yifenfei ' s hometown. On the mountain lived a big monster. As a hero in hometown, Yifenfei wants to kill it.
Now we know Yifenfei has n spells, and the monster has M hp, when HP <= 0 meaning monster is killed. Yifenfei ' s spells has different effect if used in different time. Now all you have spells ' s effects, expressed (A, M). A show the spell can cost A HP-monster in the common time. M show that is when the monster's HP <= M, using this spell can get double effect.
Inputthe input contains multiple test cases.
Each test case include, first and integers n, m (2<n<10, 1<m<10^7), express how many spells Yifenfei have.
Next n line, each line express one spell. (Ai, Mi). (0<ai,mi<=m).
Outputfor each test case output one integer, how many spells Yifenfei should with at least. If Yifenfei can not kill the monster output-1.
Sample Input
3 10010 2045 895  403 10010 2045 905 403 10010 2045 845 40
Sample Output
32-1
Authoryifenfei
The age of Source struggle
Recommendyifenfei



Topic Analysis:

Deep Search. Simple question. In fact, this problem basically no difficulty. Just read the subject.



The code is as follows:

/* * h.cpp * * Created on:2015 February 26 * author:administrator * * #include <iostream> #include <cstdio>usin G namespace Std;const int maxn = 11;struct node{//skill structure int spell;//damage value int m;//If this big trick is released, the monster's HP drizzle is the value, then the damage is spell*2 }node[maxn];bool visited[maxn];//is used to mark whether a skill has used an int ans;//kill a monster the minimum number of skills required int n;//Total skill number int hp;//Monster's energy value/** * Deep search. * k: Indicates the current number of skills * HP: The current Monster Energy value */void DFS (int k,int hp) {/** * Cross judgment */if (K >= 11) {//If all the skills have been put out of return;//Return.} /** * Determine if the */if is successful (HP <= 0) {//If the monster's energy value has been <=0if (ans > k) {//If the minimum number of skills currently saved < Current minimum skill number ans = k;//update the minimum number of skills in the bag village}return ;//Return}int i;for (i = 1; I <= n; ++i) {//Traverse all skills if (visited[i] = false) {//If the skill has not been used visited[i] = true;//mark the skill as already using if (h P <= Node[i]. M) {//If the monster's energy value <=mdfs (k+1,hp-node[i].spell*2);//Then the damage value is spell*2. Continue using the next skill}else{//otherwise DFS (K+1,hp-node[i]. spell);//This time caused the Shanghai city spell}visited[i] = false;//rollback. Mark the skill as not being accessed}}}int main () {while (scanf ("%d%d", &n,&hp)! = EOF) {int i;for (i = 1; I <= n; ++i) {scanf ("%d%d", &AMp;node[i].spell,&node[i]. M);} memset (visited,false,sizeof (visited)); ans = 11;//initialization skill minimum number of uses DFS (0,HP); if (ans = = 11) {//If ANS has not been updated printf (" -1\n") ;//Then prove that the monster was not killed}else{//otherwise, it proves that the monster was killed by printf ("%d\n", ans);//output using the minimum number of skills}}return 0;}







(Hdu step 4.2.7) Kill the Monster (there are n skills to find the minimum number of uses of the skill to kill monsters. When using a certain skill, if the monster's energy value is hp<=m, the damage is twice times the original value.

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.