您的位置:首页 > 产品设计 > UI/UE

hdu5568 sequence2

2015-11-30 11:53 501 查看
思路:题目问的是长度为k的严格上升子序列有多少种。求种数的时候一般会想到大数,也就是简单模拟下加法运算。

// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__ )
#else
#define debug(...)
#endif
#define MEM(x,y) memset(x, y,sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 100000000;//1e8
struct BigInt{
int len, p[110];
BigInt(){
memset(p, 0,sizeof p);
len = 0;
}
BigInt operator +(const BigInt& rhs)const{
BigInt cnt;
int t = max(this->len, rhs.len);
for (int i = 1;i <= t;++i){
cnt.p[i] += this->p[i] + rhs.p[i];
cnt.p[i+1] += cnt.p[i] / MOD;
cnt.p[i] = cnt.p[i] % MOD;
}
if (cnt.p[t+1])
t++;
cnt.len = t;
return cnt;
}
}dp[110][110], ans;
int A[110], s, sum, n, k;
void print(const BigInt& x){
printf("%d",x.p[x.len]);
for (int i = x.len - 1;i >= 1;--i){
printf("%08d", x.p[i]);
}
printf("\n");
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&k) != EOF){
memset(dp, 0,sizeof dp);
memset(ans.p, 0,sizeof ans.p);
ans.len = 0;
for (int i = 0;i < n;++i){
scanf("%d",&A[i]);
dp[i][1].p[1] = dp[i][1].len = 1;
}
for (int i = 1;i <= n;++i){
for (int j = 0;j < i;++j){
if (A[i] > A[j])
for (int x = 1;x < n;++x)
dp[i][x+1] = dp[i][x+1] + dp[j][x];
}
}
for (int i = 0;i < n;++i)
ans = ans + dp[i][k];
print(ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: