标签:des style c class blog code
Time
Limit: 20000/10000 MS (Java/Others) Memory Limit:
32768/32768 K (Java/Others)
Total Submission(s):
120 Accepted Submission(s):
24
#include <stdio.h> #include <string.h> #include <algorithm> #define max(a, b) ((a) > (b) ? (a) : (b)) using namespace std; const int O = 100005; typedef struct E{ int v, n, e; }E; E edge[O]; int Adj[O], l; int val[O], dp[O]; int t, n, m, cas; int d, e, s, f; void addedge(int u, int v, int e){ edge[l].v = v; edge[l].e = e; edge[l].n = Adj[u]; Adj[u] = l++; } int read(){ char ch = ‘ ‘; int x = 0; while(ch < ‘0‘ || ch > ‘9‘) ch = getchar(); while(ch >= ‘0‘ && ch <= ‘9‘){ x = x * 10 + ch - ‘0‘; ch = getchar(); } return x; } void work(){ memset(val, 0, sizeof(val)); memset(Adj, -1, sizeof(Adj)); l = 0; n = read(); m = read(); while(n--){ d = read(); e = read(); val[d] += e; } while(m--){ s = read(); f = read(); e = read(); addedge(s, f, e); } dp[100001] = 0; double ans = 0; for(int i = 100000; i; --i){ dp[i] = dp[i + 1]; for(int j = Adj[i]; ~j; j = edge[j].n){ dp[i] = max(dp[i], dp[edge[j].v] + edge[j].e); } ans += dp[i] * val[i]; } printf("%.2f\n", ans / 100); } int main(){ for(t = read(), cas = 1; cas <= t; ++cas){ printf("Case #%d:\n", cas); work(); } return 0; }
HDU 4833 Best Financing DP,布布扣,bubuko.com
标签:des style c class blog code
原文地址:http://www.cnblogs.com/ac-luna/p/3752936.html