标签:
2 1 2 1 10000 1 100 5 50 200 10 2 2 1 10000 5 20000 1 5 6 5 9 7
Case #1: 1000.00 Case #2: 2700.00
#include<stdio.h> #include<string.h> #define max(a,b) (a>b?a:b) int val[100010],head[100010],cnt; struct s { int u,v,w,next; }edge[100010]; void add(int u,int v,int w) { edge[cnt].u=u; edge[cnt].v=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++; } double dp[100010]; int main() { int n,m; int t,cot=0; scanf("%d",&t); while(t--) { memset(head,-1,sizeof(head)); memset(val,0,sizeof(val)); cnt=0; int i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { int d,e; scanf("%d%d",&d,&e); val[d]+=e; } for(i=0;i<m;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); add(a,b,c); } memset(dp,0,sizeof(dp)); double ans=0; printf("Case #%d:\n",++cot); for(i=100000;i>0;i--) { dp[i]=dp[i+1]; for(j=head[i];j!=-1;j=edge[j].next) { dp[i]=max(dp[i],dp[edge[j].v]+edge[j].w); // printf("%lf %d %d\n",dp[i],i,val[i]); } ans+=dp[i]*val[i]; } printf("%.2lf\n",ans/100); } }
HDOJ 题目4833 Best Financing(DP)
标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/46123615