AmlyC @ 2018-08-27 21:12:53
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
const int SIZE=1<<20;
inline char getch(){
static char buf[SIZE],*p1=buf,*p2=buf;
return p1==p2 && (p2=(p1=buf)+fread(buf,1,SIZE,stdin),p1==p2) ? EOF : *p1++;
}
int read(){
int s=0,f=1;
char c=getch();
while(c>'9'||c<'0'){if(c=='-') f=-1;c=getch();}
while(c>='0'&&c<='9') {s=(s<<1)+(s<<3)+c-'0';c=getch();}
return s*=f;
}
const int maxn=1000007;
int n,t,k,a[1001][1001],head[maxn],tot,vis[maxn],dis[maxn],ans[maxn];
struct node
{
int to,next,val;
}edge[maxn];
void add(int x,int y,int w){
edge[++tot].to=y,edge[tot].next=head[x],head[x]=tot,edge[tot].val=w;
}
void spfa(){
queue<int> q;
memset(dis,0,sizeof dis);
dis[1]=a[1][1],vis[1]=1;
q.push(1);
while(!q.empty()){
int u=q.front();
q.pop();
vis[u]=0;
for(int i=head[u];i;i=edge[i].next){
if(dis[edge[i].to] <= dis[u]+edge[i].val){
dis[edge[i].to] = dis[u]+edge[i].val;
if(!vis[edge[i].to]){
q.push(edge[i].to);
vis[edge[i].to]=1;
}
}
}
}
}
int main(int argc, char const *argv[])
{
memset(a,-1,sizeof a);
n=read();
fors(i,1,n){
fors(j,1,i){
a[i][j]=read();
ans[++t]=a[i][j];
}
}
k=t=1;
fors(i,1,n-1){
fors(j,1,i){
add(k+j-1,k+i,a[i+1][j]);
add(k+j-1,k+i+1,a[i+1][j+1]);
}
k+=i;
}
spfa();
k=(n*(n+1))>>1;
t=k-n;
int maxs=-1;
fors(i,t,k){
maxs=max(dis[i],maxs);
}
printf("%d\n",maxs);
return 0;
}
只有44分
by AThousandSuns @ 2018-08-27 21:38:29
大佬太强了用SPFA负优化DP转移%%%
by wxy_god @ 2018-08-27 21:47:35
by AmlyC @ 2018-08-28 15:51:41
@我是一个垃圾
我用SPFA 又A了一题· (无聊水)
AC
by wxy_god @ 2018-08-28 16:18:16
@BeyondOI
666
by GKxx @ 2018-12-25 19:15:31
@BeyondOI 我认为这题不仅可以SPFA,甚至还可以费用流