zoukankan      html  css  js  c++  java
  • HDU 2616 Kill the monster(简单DFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2616

    Kill the monster

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 594    Accepted Submission(s): 417


    Problem Description
    There 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 have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
     
    Input
    The input contains multiple test cases.
    Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
    Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
     
    Output
    For each test case output one integer that how many spells yifenfei should use at least. If yifenfei can not kill the monster output -1.
     
    Sample Input
    3 100 10 20 45 89 5 40 3 100 10 20 45 90 5 40 3 100 10 20 45 84 5 40
     
    Sample Output
    3 2 -1
     
    Author
    yifenfei
     
    Source
     
    Recommend
    yifenfei
     
     
    简单DFS搜索题。。还好1A了,不然真弱爆了。。。。
     
     By LFENG
     
    #include<stdio.h>
    #include<string.h>
    struct spell
    {
        
    int effect;
        
    int hp;
    }sp[
    30];
    int n,m,mint,HP;
    int vis[30];
    void getdata()
    {
        
    int i;
        
    for(i=0;i<n;i++)
        scanf(
    "%d %d",&sp[i].effect,&sp[i].hp);
        mint=
    9999999;
        memset(vis,
    0,sizeof(vis));
    }
    void dfs(int num,int mhp)
    {
        
    int i;
        
    if(mhp<=0)
        {
            
    if(mint>num)mint=num;
            
    return ;
        }
        
    for(i=0;i<n;i++)
        {
            
    if(vis[i])continue;
            vis[i]=
    1;
            
    if(mhp<=sp[i].hp)dfs(num+1,mhp-sp[i].effect*2);
            
    else dfs(num+1,mhp-sp[i].effect);
            vis[i]=
    0;
        }
    }
    int main()
    {
        
    int t;
        
    while(scanf("%d %d",&n,&HP)!=EOF)
        {
            getdata();
            dfs(
    0,HP);
            
    if(mint<9999999)printf("%d\n",mint);
            
    else printf("-1\n");
        }
        
    return 0;
    }
  • 相关阅读:
    触摸屏多媒体查询展示自主设计系统开发过程
    hashtable数据循环读取的顺序问题
    vs2010英文版打包中文框架出错的解决办法
    Silverlight游戏开发初探(上篇)
    PB之——编码规范
    时间相加 ,使用SQL完成
    PB(POWERBUILDER) 基础介绍
    PB之——流程控制
    PB之——基本数据类型
    PB [Grid风格数据窗口改变线条颜色] 的变通实现方法(也可以成为 带表头的Grid数据窗口)
  • 原文地址:https://www.cnblogs.com/lfeng/p/3100091.html
Copyright © 2011-2022 走看看