#include <stdio.h>
#include <algorithm>
int sum,res,i,n;
struct node
{
int hp,dsp;
void input()
{
scanf("%d%d",&dsp,&hp);
sum += dsp;
}
}hero[22];
///按单位血量的攻击力排序
bool cmp(node a,node b)
{
return a.dsp*1.0/a.hp > b.dsp*1.0/b.hp;
}
int main()
{
while(scanf("%d",&n) == 1)
{
sum = 0;
res = 0;
for(i = 0; i < n; ++i)
hero[i].input();
std::sort(hero,hero + n,cmp);
for(i = 0; i < n; ++i)
{
res += sum * hero[i].hp;
sum -= hero[i].dsp;
}
printf("%d\n",res);
}
return 0;
}
解题报告
这篇博客介绍了HDU 4310 Hero问题的解题过程,主要使用了状态压缩动态规划的方法。通过dp[mask]来表示消灭特定敌人组合所需的最小HP消耗,并通过转移方程进行优化。
订阅专栏 解锁全文
6389

被折叠的 条评论
为什么被折叠?



