Hangzhou Electric Oj_hdu2616_kill The monster

Source: Internet
Author: User

Main topic:

There was a mountain near Yifenfei's hometown, and a big monster lived in the mountains. As a hero in his hometown, Yifenfei decided to kill the monster.

Now we know Yifenfei has n spells, the Monster's blood volume is M, when the Monster's blood volume <= 0 means the monster was killed. Use different spells at different times, and there is a difference in the effect. Now, with the expression (A, M), tell you the effect of each of these spells. A means that the magic can knock out the monster a point of blood. M means that when the monster's blood volume is <= m, magic damage is doubled.

Input:

The input contains many test data. The first two integers per test n,m (2 < n < ten, 1 < m < 10^7), n represents the number of spells Yifenfei, and M represents the amount of monster blood. The next n lines, each line represents a magic (AI,MI). (0 < Ai, Mi <=m).

Output:

Each use case outputs an integer that represents the minimum number of spells that Yifenfei kills monsters. If Yifenfei can't kill monster output-1.

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 5 //data structure for recording spell damage situation6typedefstructNode7 {8     intA;9     intM;Ten }node; One  ANode spells[Ten]; - BOOLvisit[Ten];//tag Array to determine if a spell has been used - intSpellcount;//Feifei Number of spells possessed the intMincount;//The minimum number of spells needed to kill a monster -  - /*Data Initialization Functions*/ - voidInit () + { -Mincount =Ten; +memset (Visit,0,sizeof(visit)); A } at  - /*DFS Search*/ - voidDfsintCountintHP) - { -     if(Spellcount = = Count && HP >0)//all spells are exhausted, monster hp > 0, return False -         return; in     Else if(Mincount <= count && HP >0)//currently using more spells than Mincount, Monster hp > 0, description Continue search no value, return false -         return; to     Else if(Mincount > Count && HP <=0)//the number of spells currently used is smaller than mincount, and the monster HP <=0 indicates a better way to find than before. Returns True +     { -Mincount =count; the         return; *     } $ Panax Notoginseng      for(inti =0; i < Spellcount; ++i) -     { the         if(false==Visit[i]) +         { AVisit[i] =true; the             intharm = (HP <= spells[i]. M?2*Spells[i]. A:spells[i]. A); +DFS (Count +1, HP-harm); -Visit[i] =false; $         } $     } - } -  the intMainvoid) - {Wuyi     intGpt//Moster ' s HP the      while(SCANF ("%d%d", &spellcount, &hp)! =EOF) -     { Wu init (); -          for(inti =0; i < Spellcount; ++i) Aboutscanf"%d%d", &spells[i]. A, &Spells[i]. M); $Dfs0, HP); -         if(Ten!=mincount) -printf"%d\n", mincount); -         Else Aprintf"-1\n"); +     } the     return 0; -}

Hangzhou Electric Oj_hdu2616_kill The monster

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.