前三天走1-4-5,后两天走1-3-5,这样总成本为(2+2)*3+(3+2)*2+10=32
这题咋看不好做……
实际上暴力都能过……
暴力枚举第i天到第j天(不改线路)的最小费用
然后n^2暴力……这样也能过……
FJ某年OI既视感
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #include<cmath> #include<cctype> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define ForD(i,n) for(int i=n;i;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define RepD(i,n) for(int i=n;i>=0;i--) #define MAXD (10000+10) #define MAXM (800+10) #define MAXN (20+10) #define MAXDay (100+10) #define INF (2139062143) int n,m,k,day,ud; struct comm { int no,x,y; friend bool operator<(comm a,comm b){return a.x<b.x;} }ask[MAXD]; int edge[MAXM],next[MAXM]={0},pre[MAXN]={0},weight[MAXM],size=0; bool b[MAXN]={0}; void addedge(int u,int v,int w) { edge[++size]=v; weight[size]=w; next[size]=pre[u]; pre[u]=size; } int q[MAXN*8],d[MAXN]; void SPFA(int day1,int day2) { memset(b,0,sizeof(b)); memset(d,127,sizeof(d)); For(i,ud) if (!(ask[i].y<day1||ask[i].x>day2)) b[ask[i].no]=1; int head=1,tail=1;d[q[1]=1]=0; while (head<=tail) { int now=q[head]; Forp(now) { int v=edge[p]; if (!b[v]&&d[v]>d[now]+weight[p]) { d[v]=d[now]+weight[p]; q[++tail]=v; } } head++; } } int f[MAXN]; int main() { // freopen("bzoj1003.in","r",stdin); scanf("%d%d%d%d",&day,&n,&k,&m); For(i,m) {int u,v,w;scanf("%d%d%d",&u,&v,&w);addedge(u,v,w),addedge(v,u,w);} scanf("%d",&ud);For(i,ud) scanf("%d%d%d",&ask[i].no,&ask[i].x,&ask[i].y); f[0]=0; For(i,day) { f[i]=INF; Rep(j,i) { SPFA(j+1,i); if (d[n]==INF) continue; else f[i]=min(f[i],f[j]+(i-j)*d[n]+k); } } printf("%d",f[day]-=k); return 0; }