HDU 5568 sequence2 dp+ High Accuracy

Source: Internet
Author: User
Test instructions: Sequence A of length n, q How many increment sub-sequences of length k? N<=100,a[i]<=1e9.
DP[I][J]: Number of sub-sequences O (n^3) with the end length of J.

The maximum answer is C (n,k) will explode long long with high progress plus

#include <bits/stdc++.h> using namespace std;
typedef long Long LL;
const int N=1e2+5,mod=1e8;
	struct bigint{int len,p[n];
		Bigint () {memset (p,0,sizeof (p));
	len=0;
}}dp[n][n],ans;
ll N,k,a[n];
	Bigint Add (const Bigint &x,const Bigint &y) {Bigint cnt;
	int T=max (X.len,y.len);
		for (int i=1;i<=t;i++) {cnt.p[i]+=x.p[i]+y.p[i];
	cnt.p[i+1]=cnt.p[i]/mod;//Save Memory (1e8) ^i number cnt.p[i]%=mod;
	} if (cnt.p[t+1]) t++;
	cnt.len=t;
return CNT;
	} 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 () {while (cin>>n>>k) {for (int i=1;i<=n;i++) cin>>a[i];
		Memset (Dp,0,sizeof (DP));
		memset (ans.p,0,sizeof (ANS.P));
		Ans.len=1;
			for (int i=1;i<=n;i++) {dp[i][1].len=dp[i][1].p[1]=1;
					for (int j=2;j<=k;j++) {for (int p=1;p<i;p++) {if (a[i]<=a[p]) continue;
				Dp[i][j]=add (Dp[i][j],dp[p][j-1]); }} anS=add (Ans,dp[i][k]);
	} print (ANS);
} return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.