百度之星资格赛1003:度度熊与邪恶大魔王

题面不kuai了,传送门

一道简单dp题,为了刷访问量写一篇吧

n巨大

防御力10

血量1000

10*1000=104

技能1000

所以dp解决。

f[i][j]=min(f[i][j],f[i][max(0,j-p[l]+i)]+k[l]); (l=1...m)

自己理解就好了啦

ps.果真刷访问量神器

 1 // It is made by XZZ
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 #define rep(a,b,c) for(rg int a=b;a<=c;a++)
 6 #define drep(a,b,c) for(rg int a=b;a>=c;a--)
 7 #define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
 8 #define il inline
 9 #define rg register
10 #define vd void
11 typedef long long ll;
12 il int gi(){
13     rg int x=0,f=1;rg char ch=getchar();
14     while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
15     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
16     return x*f;
17 }
18 ll f[11][1001],k[1001],p[1001],a[100001],b[100001];
19 int main(){
20     int n,m;
21     while(scanf("%d%d",&n,&m)==2){
22         rep(i,1,n)a[i]=gi(),b[i]=gi();
23         rep(i,1,m)k[i]=gi(),p[i]=gi();
24         rep(i,0,10)rep(j,1,1000)f[i][j]=1000000000000000ll;
25         rep(i,0,10)rep(j,1,1000)rep(l,1,m)if(p[l]>i)
26             f[i][j]=min(f[i][j],f[i][max(0ll,j-p[l]+i)]+k[l]);
27         ll ans=0;
28         rep(i,1,n)if(f[b[i]][a[i]]==1000000000000000ll)ans=-1;
29         if(ans!=-1)rep(i,1,n)ans+=f[b[i]][a[i]];
30         printf("%I64d\n",ans);
31     }
32     return 0;
33 }
View Code

 

posted @ 2017-08-05 20:08  菜狗xzz  阅读(444)  评论(2编辑  收藏  举报