思路:

dp好题,dp[i][j]表示到前i个字符为止并且以s[i]为结尾,共有多少个长度为j的不同的子序列。

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[][], sum[];
int last[];
int main()
{
int n; ll m; string s;
while (cin >> n >> m >> s)
{
memset(dp, , sizeof dp);
memset(sum, , sizeof sum);
memset(last, -, sizeof last);
for (int i = ; i <= n; i++)
{
dp[i][] = ;
for (int j = ; j <= i; j++)
{
for (int k = ; k < ; k++)
{
if (last[k] != -)
{
int p = last[k];
dp[i][j] += dp[p][j - ];
}
}
}
last[s[i - ] - 'a'] = i;
}
for (int i = ; i <= n; i++)
{
for (int j = ; j < ; j++)
{
if (last[j] != -) sum[i] += dp[last[j]][i];
}
}
sum[] = ;
ll ans = ;
bool flg = false;
for (int i = n; i >= ; i--)
{
if (m - sum[i] <= ) { ans += m * ((ll)n - i); flg = true; break; }
ans += sum[i] * ((ll)n - i); m -= sum[i];
}
cout << (flg ? ans : -) << endl;
}
return ;
}

CF1183E/H Subsequences的更多相关文章

  1. H. Subsequences (hard version) dp

    H. Subsequences (hard version) 这个题目好难啊,根本就不知道怎么dp,看了题解,理解了好一会才会的. 首先dp[i][j] 表示前面 i  个字符,形成长度为 j  的不 ...

  2. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing

    H. Hashing time limit per test 1 second memory limit per test 512 megabytes input standard input out ...

  5. CodeForces 689D Friends and Subsequences (RMQ+二分)

    Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description Mi ...

  6. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  7. H.264视频的RTP荷载格式

    Status of This Memo This document specifies an Internet standards track protocol for the   Internet ...

  8. uva 10069 Distinct Subsequences(高精度 + DP求解子串个数)

    题目连接:10069 - Distinct Subsequences 题目大意:给出两个字符串x (lenth < 10000), z (lenth < 100), 求在x中有多少个z. ...

  9. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

随机推荐

  1. 微信小程序 空白页重定向---二维码扫描第二次进入 不经过onLoad过程解析scene参数,跳转问题

    在刚开始的时候将小程序的入口文件直接指向tabbar 的首页,此时出现问题:二维码扫描,第一次不关闭首页,第二次进入时:不会经过onLoad过程解析scene参数: 官方中解释:tabbar跳转方式触 ...

  2. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  3. django使用mysql的时区问题解决

    1.如果是linux 将系统的时区表导入mysql. mysql_tzinfo_to_sql /usr/share/zoneinfo 2.如果是windows 下载时区表 然后导入时区表,file_n ...

  4. 在Android中使用OpenGL ES开发第(五)节:GLSL基础语法

    一.前期基础储备笔者之前的四篇文综述了Android中使用OpenGL ES绘制基本图形和实现了简单的相机预览,初次接触OpenGL ES开发的读者可能对其中新的概念比较迷惑,尤其是其中的顶点着色器( ...

  5. 删数问题(SDUT2072 )

    删数问题 Time Limit: 1000 msMemory Limit: 65536 KiB Problem Description 键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字 ...

  6. org.hibernate.TypeMismatchException: Provided id of the wrong type for class *** Expected ***

    今天上生产发现warn日志有异常,就查看了下: 2018-12-05 10:05:05.666 [pool-4-thread-1] ERROR org.springframework.batch.co ...

  7. python中的匿名函数

    python 使用 lambda 来创建匿名函数. 所谓匿名,意即不再使用 def 语句这样标准的形式定义一个函数. lambda 只是一个表达式,函数体比 def 简单很多. lambda的主体是一 ...

  8. oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )

    create table demo(id int,name varchar(20),nums int); ---- 创建表insert into demo values(1, '苹果', 1000); ...

  9. RES协议和断网访问URL出现的错误页面

    # 11 Id: 26a4.1470 Suspend: 1 Teb: 7ff9f000 Unfrozen # Memory ChildEBP RetAddr Args to Child 00 01ca ...

  10. DML:增、删、改表中数据

    1. 添加数据 (1) 常规添加 INSERT INTO 表名(列名,列名,列名) VALUES(值,值,值); (2) 简化添加 INSERT INTO 表名 VALUES(值,值,值); 规则: ...