题意:
求出所有的最长上升子序列的个数且每个元素只能用一次
解析:
呵。。。呵。。。呵。。呵。。emm。。。
再见 我死了。。。wa了15发之后。。。原来不能用~ 要用 != EOF
这题算水题吧。。。emm。。。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int s, t, n, m;
int dp[maxn], num[maxn];
int head[maxn], cur[maxn], d[maxn], cnt; struct node
{
int u, v, c, next;
}Node[]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u, int v, int c)
{
add_(u, v, c);
add_(v, u, );
} bool bfs()
{
mem(d, );
queue<int> Q;
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i = head[u]; i != -; i = Node[i].next)
{
node e = Node[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[u] + ;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
int ret = ;
if(u == t || cap == )
return cap;
for(int &i = cur[u]; i != -; i = Node[i].next)
{
node e = Node[i];
if(d[e.v] == d[u] + && e.c > )
{
int V = dfs(e.v, min(e.c, cap));
Node[i].c -= V;
Node[i ^ ].c += V;
ret += V;
cap -= V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur, head, sizeof(head));
ans += dfs(s, INF);
}
return ans;
} int main()
{
while(scanf("%d", &n) != EOF)
{
mem(head, -);
cnt = ;
s = , t = n * + ;
mem(dp, );
int max_len = -INF;
for(int i = ; i <= n; i++)
{
rd(num[i]);
dp[i] = ;
for(int j = ; j < i; j++)
if(num[j] < num[i] && dp[j] + >= dp[i]) dp[i] = dp[j] + ;
max_len = max(max_len, dp[i]);
} for(int i = ; i <= n; i++)
{
add(i, i + n, );
if(dp[i] == ) add(s, i, );
if(dp[i] == max_len) add(i + n, t, );
for(int j = i + ; j <= n; j++)
{
if(dp[i] + == dp[j])
add(i + n, j, );
}
}
cout << max_len << endl;
cout << Dinic() << endl;
} return ;
}