HDU 3008 Warcraft

哎,折磨死人的dp题,反正对于我来说是的,看了其他大牛们的代码过的,惭愧。。。。。

#include<stdio.h>
#include<string.h>
int n,t,q;
int
skillCost[110];
int
skillhurt[110];
int
dp[110];//dp[i][j]表示第i轮攻击,boss还剩下j滴hp时候剩下的最大mp
int max(int a,int b)
{

    return
a>b?a:b;
}

int
main()
{

    while
(scanf("%d%d%d",&n,&t,&q))
    {

        if
(n==0&&t==0&&q==0){break;}
        int
T;
        if
(100%q!=0)
        {

            T=100/q+1;
        }
else
        {

            T=100/q;
        }

        memset(dp,-1,sizeof(dp));
        dp[100]=100;
        int
i,j,k;
        for
(i=1;i<=n;i++)
        {

            scanf("%d%d",&skillCost[i],&skillhurt[i]);
        }

        skillCost[0]=0;
        skillhurt[0]=1;
        bool
flag=false;
        for
(i=1;i<=T;i++)
        {

            for
(j=1;j<=100;j++)
            {

                if
(dp[j]!=-1)
                {

                    for
(k=0;k<=n;k++)
                    {

                        if
(j<=skillhurt[k]&&dp[j]>=skillCost[k])
                        {

                            printf("%d\n",i);
                            flag=true;
                            break
;
                        }

                        else if
(j>skillhurt[k]&&dp[j]>=skillCost[k])
                        {

                            dp[j-skillhurt[k]]=max(dp[j-skillhurt[k]],dp[j]-skillCost[k]+t);
                        }
                    }

                }

                if
(flag==true){break;}
            }

            if
(flag==true){break;}
        }


        if
(flag==false)printf("My god\n");
    }
}

你可能感兴趣的:(HDU)