先离散化,然后逆着dp,求出每个点能取到的最大利益,然后看有没有钱,有钱就投
想法好复杂
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string> 10 #include <math.h> 11 #include <stdlib.h> 12 #include <time.h> 13 using namespace std; 14 struct NN1 15 { 16 int d,e; 17 void input() 18 { 19 scanf("%d%d",&d,&e); 20 } 21 }node1[3000]; 22 struct NN2 23 { 24 int start,finish; 25 int r; 26 void input() 27 { 28 scanf("%d%d%d",&start,&finish,&r); 29 } 30 }node2[3000]; 31 int a[5010]; 32 long long f[100010]; 33 long long f2[5010]; 34 int dp[5010]; 35 36 vector<int>vec[5010]; 37 vector<int>vec2[5010]; 38 int main() 39 { 40 //freopen("in.txt","r",stdin); 41 //freopen("out.txt","w",stdout); 42 int T; 43 int iCase = 0; 44 int n,m; 45 scanf("%d",&T); 46 while(T--) 47 { 48 iCase++; 49 printf("Case #%d: ",iCase); 50 scanf("%d%d",&n,&m); 51 int cnt = 0; 52 memset(f,0,sizeof(f)); 53 for(int i = 0;i < n;i++) 54 { 55 node1[i].input(); 56 //a[cnt++] = node1[i].d; 57 f[node1[i].d] += node1[i].e; 58 } 59 for(int i = 1;i <= 100000;i++) 60 f[i] += f[i-1]; 61 for(int i = 0;i < m;i++) 62 { 63 node2[i].input(); 64 a[cnt++] = node2[i].start; 65 a[cnt++] = node2[i].finish; 66 } 67 sort(a,a+cnt); 68 cnt = unique(a,a+cnt) - a; 69 map<int,int>mp; 70 for(int i = 0;i < cnt;i++) 71 mp[a[i]] = i; 72 f2[0] = f[a[0]]; 73 for(int i = 1;i < cnt;i++) 74 f2[i] = f[a[i]] - f[a[i-1]]; 75 for(int i = 0;i < cnt;i++) 76 { 77 vec[i].clear(); 78 vec2[i].clear(); 79 } 80 for(int i = 0;i < m;i++) 81 { 82 node2[i].start = mp[node2[i].start]; 83 node2[i].finish = mp[node2[i].finish]; 84 vec[node2[i].start].push_back(node2[i].finish); 85 vec2[node2[i].start].push_back(node2[i].r); 86 } 87 memset(dp,0,sizeof(dp)); 88 for(int i = cnt-1;i >= 0;i--) 89 { 90 dp[i] = dp[i+1]; 91 int sz = vec[i].size(); 92 for(int j = 0;j < sz;j++) 93 dp[i] = max(dp[i],dp[vec[i][j]] + vec2[i][j]); 94 } 95 long long ans ; 96 //minCostMaxflow(cnt,cnt+1,ans); 97 ans = 0; 98 for(int i = 0;i < cnt;i++) 99 { 100 ans += (long long)dp[i]*f2[i]; 101 } 102 printf("%.2lf ",(double)ans/100); 103 104 } 105 return 0; 106 }