HDU 5568 DP大数

sequence2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 234    Accepted Submission(s): 97


Problem Description
Given an integer array $b_i$ with a length of $n$, please tell me how many exactly different increasing subsequences.

P.S. A subsequence $b_{a_i}(1 \leq i \leq k)$ is an increasing subsequence of sequence $b_i(1 \leq i \leq n)$ if and only if $1\leq a_1 < a_2 < ... < a_k \leq n$ and $ b_{a_1} < b_{a_2} < ... < b_{a_k} $.
Two sequences $a_i$ and $b_i$ is exactly different if and only if there exist at least one $i$ and $a_i \neq b_i$.
 

Input
Several test cases(about $5$)

For each cases, first come 2 integers, $n,k(1 \leq n \leq 100,1 \leq k \leq n)$

Then follows $n$ integers $a_i ( 0 \leq a_i \leq 10^9)$
 

Output
For each cases, please output an integer in a line as the answer.
 

Sample Input
  
  
3 2 1 2 2 3 2 1 2 3
 

Sample Output
  
  
2 3
 
看别人代码学习的
 
#include <cstdio> #include <cstring> #include <algorithm> #define LEN 110 #define MOD 100000000 using namespace std; struct BigInt {     int len,p[LEN];     BigInt() {         memset(p,0,sizeof(p));         len=0;     } }dp[105][105],ans; int a[105],s,num,n,k,t; BigInt add(const BigInt& x,const BigInt& y) {     BigInt cnt;     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;         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(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]=add(dp[i][x+1],dp[j][x]);         for(int i=0;i<n;++i)             ans=add(ans,dp[i][k]);         print(ans);     }     return 0; }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值