标签:scan sync play fas 不能 pair native its #define
https://www.lydsy.com/JudgeOnline/problem.php?id=1003
数据范围很小,怎么瞎搞都行,n方dp,然后跑出最短路暴力转移,需要注意的是不能使用的可能有多个区间
/************************************************************** Problem: 1003 User: walfy Language: C++ Result: Accepted Time:180 ms Memory:1400 kb ****************************************************************/ //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> #define cd complex<double> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double eps=1e-6; const int N=100+10,maxn=5000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f; struct edge{ int to,Next,c; }e[maxn]; int head[N],cnt,ban[N][N]; void add(int u,int v,int c) { e[cnt].to=v; e[cnt].c=c; e[cnt].Next=head[u]; head[u]=cnt++; } void init() { cnt=0; memset(head,-1,sizeof head); } priority_queue<pair<int,int> >q; int dis[N],dp[N]; int n,m,K,E; int dij(int be,int en) { q.push(mp(0,1)); memset(dis,inf,sizeof dis); dis[1]=0; while(!q.empty()) { pii u=q.top(); q.pop(); int x=u.se; if(dis[x]<u.fi)continue; for(int i=head[x];~i;i=e[i].Next) { int To=e[i].to; bool ok=1; for(int j=be;j<=en;j++) if(ban[To][j]) ok=0; if(ok) { if(dis[To]>dis[x]+e[i].c) { dis[To]=dis[x]+e[i].c; q.push(mp(dis[To],To)); } } } } if(dis[m]==inf)return -1; else return dis[m]*(en-be+1); } int main() { scanf("%d%d%d%d",&n,&m,&K,&E); init(); for(int i=0;i<E;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); add(a,b,c); add(b,a,c); } int d;scanf("%d",&d); while(d--) { int p,a,b;scanf("%d%d%d",&p,&a,&b); for(int i=a;i<=b;i++)ban[p][i]=1; } memset(dp,inf,sizeof dp); dp[0]=-K; for(int i=1;i<=n;i++) { for(int j=0;j<i;j++) { int dis=dij(j+1,i); if(dis>0)dp[i]=min(dp[i],dp[j]+dis+K); } } printf("%d\n",dp[n]); return 0; } /******************** ********************/
标签:scan sync play fas 不能 pair native its #define
原文地址:https://www.cnblogs.com/acjiumeng/p/9056827.html