HDU 2616 Kill the monster(生成排列)

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

 

#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;

const int INF = 1 << 30;


struct ka
{
    int A, M;
}a[11];

int main()
{

    int i, j;
    int ans;
    int n, init_hp;
    int p[11];
    while (~scanf("%d%d", &n, &init_hp))
    {
        for (i = 0; i < n; i++)
        {
            scanf("%d%d", &a[i].A, &a[i].M);
        }
        for (i = 0; i < n; i++)
        {
            p[i] = i;
        }
        
        ans = INF;
        do
        {
            int hp = init_hp;
            for (i = 0; i < n; i++)
            {
                
                if (hp <= a[p[i]].M)
                {
                    hp -= 2 * a[p[i]].A;
                }
                else
                {
                    hp -= a[p[i]].A;
                }

                if (hp <= 0)//一杀死马上退出循环,以便后面判断是否杀死。
                {
                    break;
                }
            }
            
            if (ans > i)//i:0--->n-1
            {
                ans = i;
            }
        }while (next_permutation(p, p + n));

        if (ans == n)
        {
            puts("-1");
        }
        else
        {
            printf("%d\n", ans+1);
        }
    }

    return 0;
}



posted on 2012-04-09 17:01  [S*I]SImMon_WCG______*  阅读(205)  评论(0编辑  收藏  举报

导航