加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

hdu5568 sequence2

发布时间:2020-12-14 02:11:33 所属栏目:大数据 来源:网络整理
导读:思路:题目问的是长度为k的严格上升子序列有多少种。求种数的时候一般会想到大数,也就是简单模拟下加法运算。 // #pragma comment(linker,"/STACK:1024000000,1024000000")#include iostream#include algorithm#include iomanip#include sstream#include st

思路:题目问的是长度为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,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,sizeof dp);
		memset(ans.p,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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读