hdu 6611 K Subsequence(最大费用流)

hdu6611

（出题人卡$spfa$费用流还是比较骚的。。）

#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MAXN_ 100005
#define INF 0x3f3f3f3f
#define P pair<int,int>
using namespace std;
struct edge
{
int to,cap,cost,rev;
};
int n,m,flow,s,t,res,h[MAXN_];
vector<edge> G[MAXN_];
int dist[MAXN_],prevv[MAXN_],preve[MAXN_]; // 前驱节点和对应边
inline void addEdge(int u,int v,int cap,int cost)
{
//G[u].push_back(edge(v,cap,cost,G[u].size()));
G[u].push_back((edge)
{
v,cap,cost,(int)G[v].size()
});
G[v].push_back((edge)
{
u,0,-cost,(int)G[u].size()-1
});
} // 在vector 之中找到边的位置所在!
inline void min_cost_flow(int s,int t,int f)
{
fill(h+1,h+1+m,0);
flow = res = 0;
while(f > 0)
{
priority_queue<P,vector<P>, greater<P> > D;
memset(dist,INF,sizeof dist);
dist[s] = 0;
D.push(P(0,s));
while(!D.empty())
{
//puts("ss");
P now = D.top();
D.pop();
if(dist[now.second] < now.first) continue;
int v = now.second;
for(int i=0; i<(int)G[v].size(); ++i)
{
edge &e = G[v][i];
if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to])
{
dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
prevv[e.to] = v;
preve[e.to] = i;
D.push(P(dist[e.to],e.to));
}
}
}
// 无法增广 ， 就是找到了答案了！

if(dist[t] == INF) break;
for(int i=1; i<=m; ++i) h[i] += dist[i];
int d = f;
for(int v = t; v != s; v = prevv[v])
d = min(d,G[prevv[v]][preve[v]].cap);
f -= d;
//printf("%d\n",f);
flow += d;
res += d * h[t];
for(int v=t; v!=s; v=prevv[v])
{
edge &e = G[prevv[v]][preve[v]];
e.cap -= d;
G[v][e.rev].cap += d;
}
}
}

int k;
int a[MAXN_];
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
for(int i = 0; i <= 2*n+2; i++) G[i].clear();
for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
int st = 0,ed = n+n+1;
m = 2*n+2; //点的总个数
for(int i = 1; i <= n; i++){ //源点到数
}
for(int i = 1; i <= n; i++){　//拆点
for(int j = i+1; j <= n; j++){　//小到大
}
}
int  supered = n+n+2;