hdu4833 Best Financing(dp)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                hdu4833 Best Financing(dp)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                hdu4833
題目
中文題目
思路
還是很菜啊,首先點很多所以要離散化,其次還是思路上的問題吧,獲得的每一筆錢之間是互相沒有關(guān)系的,我們只要考慮把它進行哪幾次投資以獲得最大的rate,然后加起來就行了,對于最大的rate,將時間連成一張有向圖,根據(jù)時間序以及產(chǎn)品給的起止時間,然后就類似數(shù)塔進行dp即可。
代碼
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<stack> #include<cstdlib> #include<algorithm> #include<cmath>using namespace std;typedef long long ll;const int maxn=25100; int d[maxn],e[maxn],s[maxn],f[maxn],r[maxn]; int point[maxn*4]; int tot,num; int dp[maxn*4]; int head[maxn*4]; struct node {int next;int to;int w; } edge[maxn];void addedge(int from,int to,int w) {edge[tot].to=to;edge[tot].next=head[from];edge[tot].w=w;head[from]=tot++; }int getnum(int x) {return lower_bound(point,point+num,x)-point; }void solve(int n) {memset(dp,0,sizeof(dp));for(int i=n-1; i>=0; i--){for(int j=head[i]; ~j; j=edge[j].next){int v=edge[j].to;int w=edge[j].w;dp[i]=max(dp[i],dp[v]+w);}} }int main() {int T;scanf("%d",&T);int kase=1;while(T--){memset(head,-1,sizeof(head));tot=0;int n,m;scanf("%d %d",&n,&m);for(int i=0; i<n; i++){scanf("%d %d",&d[i],&e[i]);point[tot++]=d[i];}for(int i=0; i<m; i++){scanf("%d %d %d",&s[i],&f[i],&r[i]);point[tot++]=s[i],point[tot++]=f[i];}sort(point,point+tot);num=unique(point,point+tot)-point;tot=0;for(int i=1; i<num; i++) addedge(i-1,i,0);for(int i=0; i<m; i++){int a=getnum(s[i]);int b=getnum(f[i]);addedge(a,b,r[i]);}solve(num);ll ans=0;for(int i=0; i<n; i++){ans+=(ll)e[i]*dp[getnum(d[i])];}printf("Case #%d:\n",kase++);printf("%I64d.%02d\n",ans/100,ans%100);}return 0; }總結(jié)
以上是生活随笔為你收集整理的hdu4833 Best Financing(dp)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Seastar Tutorial 简明教
- 下一篇: 逆地理编码-离线版-part2
