栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2021牛客国庆集训派对day1 -Removal(动态规划)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021牛客国庆集训派对day1 -Removal(动态规划)

Removal

  •  比赛主页
  •  我的提交

时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述 

Bobo has a sequence of integers s1, s2, ..., sn where 1 ≤ si ≤ k.
Find out the number of distinct sequences modulo (109+7) after removing exactly m elements.

输入描述:
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains three integers n, m and k.
The second line contains n integers s1, s2, ..., sn.
输出描述:
For each test case, print an integer which denotes the result.

示例1

输入

复制

3 2 2
1 2 1
4 2 2
1 2 1 2
输出

复制

2
4
备注:
* 1 ≤ n ≤ 105
* 1 ≤ m ≤ min{n - 1, 10}
* 1 ≤ k ≤ 10
* 1 ≤ si ≤ k
* The sum of n does not exceed 106.
const int MAX=1010;
const int MOD=1e9;
int n,m,k;
int a[1000010];
int pre[100010];
int id[1000010];
int dp[MAX][20]; //dp[i][j]是指到第i位的已经删除了j位数字
//但是要注意当前位置的数字在之前已经删除过了 所以要判断当前位置的i-pre是否大于j
int main(){
    while(cin>>n>>m>>k){
        mms(pre,0);
        mms(id,0);
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            pre[i]=id[a[i]];
            id[a[i]]=i;
        }
        mms(dp,0);
        for(int i=0;i<=m;i++){
            dp[i][i]=1;
        }
        for(int i=1;i<=n;i++){
            int d=i-pre[i];
            dp[i][0]=1;
            for(int j=1;j<=m;j++){
                if(j>i)break;
                dp[i][j]=((dp[i-1][j-1]+dp[i-1][j])%MOD+MOD)%MOD;
                if(pre[i]!=0&&d<=j){
                    dp[i][j]=((dp[i][j]-dp[pre[i]-1][j-d])%MOD+MOD)%MOD;
                }
            }
        }
        cout< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/289526.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号