HDU 2616 Kill the monster

题意:。。

搜索,超暴力

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;
const int INF = 0x7ffffff;
int n,m;
int A[19],M[19];
void init()
{
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&A[i],&M[i]);
    }
}
bool v[19];
int ans;
void dfs(int dep,int s)
{
    if(s<=0)
    {
        ans=min(ans,dep);
        return ;
    }
    for(int i=0;i<n;i++)
    if(!v[i])
    {
        v[i] = true;
        dfs(dep+1,(s<=M[i])?s-2*A[i]:s-A[i]);
        v[i] = false;
    }
}
void solve()
{
    memset(v,0,sizeof(v));
    ans = INF;
    dfs(0,m);
    if(ans==INF)
    {
        printf("-1\n");
    }else{
        printf("%d\n",ans);
    }
}
int main()
{
    freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m))
    {
        init();
        solve();
    }
    return 0;
}


你可能感兴趣的:(HDU 2616 Kill the monster)