标签:fstream lan algo lis 链接 += cti exception def
[题目链接]
http://poj.org/problem?id=1952
[算法]
DP
[代码]
#include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <map> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <stack> #include <limits.h> using namespace std; #define MAXN 5010 int i,j,n,ans1,ans2; int a[MAXN],f[MAXN],g[MAXN]; int main() { scanf("%d",&n); for (i = 1; i <= n; i++) { scanf("%d",&a[i]); f[i] = g[i] = 1; } for (i = 1; i <= n; i++) { for (j = i - 1; j >= 1; j--) { if (a[j] > a[i]) { if (f[j] + 1 > f[i]) { f[i] = f[j] + 1; g[i] = g[j]; } else if (f[j] + 1 == f[i]) g[i] += g[j]; } else if (a[i] == a[j]) { if (f[i] == 1) g[i] = 0; break; } } } for (i = 1; i <= n; i++) { if (f[i] > ans1) { ans1 = f[i]; ans2 = g[i]; } else if (f[i] == ans1) ans2 += g[i]; } printf("%d %d\n",ans1,ans2); return 0; }
标签:fstream lan algo lis 链接 += cti exception def
原文地址:https://www.cnblogs.com/evenbao/p/9349816.html