Codeforces 360C Levko and Strings dp
来源:互联网 发布:贵州师范大学网络平台 编辑:程序博客网 时间:2024/04/27 19:05
题目链接:点击打开链接
题意:
给定长度为n的字符串s,常数k
显然s的子串一共有 n(n-1)/2 个
要求找到一个长度为n的字符串t,使得t对应位置的k个子串字典序>s
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<vector>#include<set>using namespace std;#define N 2505#define mod 1000000007#define ll __int64ll n,k;ll dp[N][N];//dp[i][j]表示i位置产生的j对(1-i-1都是相同的)char s[N];ll num[N], sum[N];ll work(){if(k==0)return num[1];dp[0][0] = 1;sum[0] = 1;ll ans = 0;for(ll i = 1; i <= n; i++){ll len = n-i+1;for(ll j = 0; j <= k; j++) {for(ll z = i-1; z>=0 && (i-z)*len<=j; z--) {dp[i][j] = (dp[i][j]+dp[z][j-(i-z)*len])%mod;}dp[i][j] = dp[i][j]*('z'-s[i])%mod;}ans = (ans+dp[i][k]*num[i+1]%mod)%mod;for(ll j = 0; j <= k; j++) {dp[i][j] = (dp[i][j]+sum[j]*(s[i]-'a')%mod)%mod;sum[j] = (sum[j]+dp[i][j])%mod;}}return ans;}int main(){ll i;while(cin>>n>>k){cin>>s+1;num[n+1] = 1;for(i=n;i;i--)num[i] = num[i+1]*(s[i]-'a'+1)%mod;cout<<work()<<endl;}return 0;}
0 0
- Codeforces 360C Levko and Strings (dp)
- Codeforces 360C Levko and Strings dp
- Codeforces 360C - Levko and Strings 组合数学+DP
- Codeforces Round #210 (Div. 1) problem C Levko and Strings
- Codeforces Round #210 (Div. 1) C. Levko and Strings
- codeforces 360B Levko and Array (dp神题)
- CodeForces 360 B.Levko and Array(二分+dp)
- 【codeforces】477C Dreamoon and Strings dp
- Codeforces 360B Levko and Array
- Codeforces #360B: Levko and Array 题解
- [codeforces]Levko and Permutation
- Levko and Permutation CodeForces
- Levko and Permutation CodeForces
- Levko and Table CodeForces
- CodeForces 361D Levko and Array(二分+dp)
- Codeforces 361D Levko and Array【二分+dp】好题!
- Dreamoon and Strings - CodeForces #272 (Div. 1) C dp
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- PHP安装的一些库
- Xshell配置ssh免密码登录-密钥公钥(Public key)与私钥(Private Key)登录
- 第6题:C++课程设计1.0版
- c++课程设计
- java代码client
- Codeforces 360C Levko and Strings dp
- Swift的74个标准函数
- C++课程设计报告
- KMP算法与BF算法
- Jxl操作相关知识
- Java学习总结15——Servlet中forward、include、redirect区别
- AC之殇
- Linux下修改键盘默认布局
- Linux下如何运行一个QT的程序