bzoj 3928: [Cerc2014] Outer space invaders
生活随笔
收集整理的這篇文章主要介紹了
bzoj 3928: [Cerc2014] Outer space invaders
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
$f[i][j]$表示消滅起始時間在$(i,j)$內的外星人所花費的最小代價。
考慮在這個區間內距離最遠的外星人h,在他的區間中一定要選一個點要開一炮,而且這一炮可以順便把其他跨過這個點的敵人消滅,剩下只需消滅沒有跨過這個點的敵人。
枚舉開炮時間$f[i][j]=min(f[i][k]+f[k][j]+d[h])$.
區間需要離散化。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 605 using namespace std; int n; int li[N],cnt; int a[N],b[N],d[N]; int f[N][N]; int main() {int cas;scanf("%d",&cas);while(cas--){scanf("%d",&n);cnt=0;for(int i=1;i<=n;i++){scanf("%d%d%d",&a[i],&b[i],&d[i]);li[++cnt]=a[i];li[++cnt]=b[i];}sort(li+1,li+cnt+1);cnt=unique(li+1,li+cnt+1)-li-1;for(int i=1;i<=n;i++){a[i]=lower_bound(li+1,li+cnt+1,a[i])-li;b[i]=lower_bound(li+1,li+cnt+1,b[i])-li;}cnt++;for(int l=0;l<=cnt;l++){for(int i=0;i<=cnt-l;i++){int j=i+l;int h=-1;for(int k=1;k<=n;k++){if(a[k]>i&&b[k]<j){if(h==-1||d[k]>d[h])h=k;}}if(h==-1)f[i][j]=0;else{f[i][j]=0x3f3f3f3f;for(int k=a[h];k<=b[h];k++){f[i][j]=min(f[i][j],f[i][k]+f[k][j]+d[h]);}}}}printf("%d\n",f[0][cnt]);}return 0; }
?
轉載于:https://www.cnblogs.com/ezyzy/p/6659204.html
總結
以上是生活随笔為你收集整理的bzoj 3928: [Cerc2014] Outer space invaders的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 赠票 | 互联网大厂的数据治理与资产管理
- 下一篇: 西瓜视频app如何添加合集(高清免费在线