hdu5568

sequence2

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


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

P.S. A subsequence  bai(1ik)  is an increasing subsequence of sequence  bi(1in)  if and only if  1a1<a2<...<akn  and  ba1<ba2<...<bak .
Two sequences  ai  and  bi  is exactly different if and only if there exist at least one  i  and  aibi .
 

Input
Several test cases(about  5 )

For each cases, first come 2 integers,  n,k(1n100,1kn)

Then follows  n  integers  ai(0ai109)
 

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
 


比赛时,一直wr,固执的以为是有坑,比赛结束后,看到别人的代码,中有大数,才发现原来是要用大数。不过这该怎么贴链接?该大数时就大数呀,风风火火闯九州呀!!!!!

(番茄酱+青菜饭,还有一份肉,好吃偷笑

ac的代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define N 110

int dp[N][N][N];
int num[N];
int ans[N];

void sum(int *a,int *b){
    int jinwei=0;

    for(int i=0;i<N;i++){
        a[i]+=b[i]+jinwei;
        jinwei=a[i]/10;
        a[i]%=10;
    }

    return;
}

int main(){
    int n,k;

    while(scanf("%d%d",&n,&k)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%d",&num[i]);
        }

        num[0]=-1;
        memset(dp,0,sizeof(dp));
        memset(ans,0,sizeof(ans));
        dp[0][0][0]=1;

        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                if(num[i]>num[j]){
                    for(int p=0;p<k;p++){
                        sum(dp[i][p+1],dp[j][p]);
                    }
                }
            }
            sum(ans,dp[i][k]);
        }

        bool pd=false;
        for(int i=N-1;i>=0;i--){
            if(ans[i]==0&&pd==false){
                continue;
            }
            else{
                if(pd==false){
                    pd=true;
                }
                printf("%d",ans[i]);
            }
        }
        if(pd==false){
            printf("0");
        }
        printf("\n");

        /*for(int i=0;i<=n;i++){
            for(int j=0;j<=k;j++){
                printf("%d ",dp[i][j][0]);
            }
            printf("\n");
        }*/
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值