# HDU - 5406

## 題目鏈接：HDU - 5406

AC代碼：

``````#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=2e3+10,M=1e6+10;
int n,s,s1,t,d[N],st[N],vis[N],cost;
struct node{int h,d;}q[N];
int cmp(node a,node b){return a.h==b.h?a.d<b.d:a.h>b.h;}
inline void ade(int a,int b,int c,int d){
}
inline int spfa(){
stack<int> q; q.push(s); memset(st,0,sizeof st); memset(d,inf,sizeof d); d[s]=0;
while(q.size()){
int u=q.top();	q.pop();	vis[u]=0;
if(flow[i]&&d[to[i]]>d[u]+w[i]){
d[to[i]]=d[u]+w[i];
if(!vis[to[i]])	q.push(to[i]),vis[to[i]]=1;
}
}
}
return d[t]<inf;
}
int dfs(int x,int f){
if(x==t)	return cost-=d[t]*f,f;
st[x]=1;	int fl=0;
if(flow[i]&&!st[to[i]]&&d[to[i]]==d[x]+w[i]){
int mi=dfs(to[i],min(flow[i],f));
flow[i]-=mi,flow[i^1]+=mi,fl+=mi,f-=mi;
}
}
return fl;
}
inline void solve(){
for(int i=1;i<=n;i++)	scanf("%d %d",&q[i].h,&q[i].d);
for(int i=1,mi;i<=n;i++){
mi=inf;
for(int j=i+1;j<=n;j++)	if(q[j].d>=q[i].d&&q[j].d<mi){
}
}
cost=0;	while(spfa())	dfs(s,inf);
printf("%d\n",cost);
}
signed main(){
int T;	cin>>T;
while(T--)	solve();
return 0;
}
``````