2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)
生活随笔
收集整理的這篇文章主要介紹了
2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
H-The Boomsday Project
Code1
暴力我為人人區間轉移
O{N∑qlog?N}O\{N\sum q\log N \}O{N∑qlogN}
不需要區間覆蓋轉移,不難發現只需轉移右端點即可。由于具有單調性可以雙指針預處理。
Code2
#include<bits/stdc++.h> using namespace std; using ll=long long; template <class T=int> T rd() {T res=0;T fg=1;char ch=getchar();while(!isdigit(ch)) {if(ch=='-') fg=-1;ch=getchar();}while( isdigit(ch)) res=(res<<1)+(res<<3)+(ch^48),ch=getchar();return res*fg; }int n,m;ll R; int tot; struct nodea {int d,k,c; }a[510]; int g[300010]; ll f[300010]; struct nodeb {int p,q;bool operator<(const nodeb &o)const{return p<o.p;} }b[300010]; int to[510][300010]; int main() {n=rd(),m=rd();R=rd<ll>();for(int i=1;i<=n;i++) a[i].d=rd(),a[i].k=rd(),a[i].c=rd();for(int i=1;i<=m;i++) b[i].p=rd(),b[i].q=rd();sort(b+1,b+1+m);for(int i=1;i<=m;i++){for(int j=tot+1;j<=tot+b[i].q;j++) g[j]=b[i].p; //第j次騎車在第b[i].p天tot+=b[i].q;}for(int j=1;j<=n;j++)for(int i=0,k=1;i<tot;i++){while(k<=tot&&g[k]-g[i+1]+1<=a[j].d) k++;to[j][i]=k-1;}memset(f,0x3f,sizeof f);f[0]=0;for(int i=0;i<tot;i++){f[i+1]=min(f[i+1],f[i]+R);for(int j=1;j<=n;j++) {int r=min(i+a[j].k,to[j][i]);f[r]=min(f[r],f[i]+a[j].c);}}printf("%lld\n",f[tot]);return 0; }總結
以上是生活随笔為你收集整理的2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020 ICPC亚洲区域赛(沈阳)F-
- 下一篇: codeforces1012 B. Ch