您的位置:首页 > 其它

HDU 2616 Kill the monster

2011-12-24 18:26 387 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2616

枚举所有情况,STL直接生成排列

View Code

#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,m,a[10],b[10],p[10],ans,i;
while (scanf("%d%d",&n,&m)!=EOF)
{
ans=n+1;
for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
for (i=1;i<=n;i++) p[i]=i;
do{
int t=m;
for (i=1;i<=n;i++)
{
if (t<=b[p[i]]) t-=a[p[i]]*2;
else t-=a[p[i]];
if (t<=0) break;
}
if (i<ans) ans=i;
}while (next_permutation(p+1,p+n+1));
if (ans>n) ans=-1;
printf("%d\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: