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(1≤i≤k) is an increasing subsequence of sequence bi(1≤i≤n) if and only if 1≤a1<a2<...<ak≤n and ba1<ba2<...<bak .
Two sequences ai and bi is exactly different if and only if there exist at least one i and ai≠bi .
P.S. A subsequence bai(1≤i≤k) is an increasing subsequence of sequence bi(1≤i≤n) if and only if 1≤a1<a2<...<ak≤n and ba1<ba2<...<bak .
Two sequences ai and bi is exactly different if and only if there exist at least one i and ai≠bi .
Input
Several test cases(about
5
)
For each cases, first come 2 integers, n,k(1≤n≤100,1≤k≤n)
Then follows n integers ai(0≤ai≤109)
For each cases, first come 2 integers, n,k(1≤n≤100,1≤k≤n)
Then follows n integers ai(0≤ai≤109)
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;
}