Cipher CodeForces
来源:互联网 发布:host 端口 配置文件 编辑:程序博客网 时间:2024/06/14 16:48
链接:http://codeforces.com/problemset/problem/156/C
题意:(太长,没仔细读,其实也看不懂)大概就是t组字符串, 对于每一组,在总的值不变的情况下问有多少中组成形式(值:a=1, b=2, c=3…., 并且范围在a-z)
解题思路:
对于长度为i 总值为j的字符串,它的组成形式数量等于长度为 i-1, 值为j-1至j-26的加和(j-x<0的情况除外)即dp[i][j]=dp[i-1][j-1]+dp[i-1][j-2]…dp[i-1][j-26], 从dp[1][1]向上推就好了
注意:因为最多有10000组数据, 所以记录所有数据中的最大值,推一遍即可
代码:
#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#define LL long longusing namespace std;const int Max=210;const int MOD=1e9+7;char str[Max];pair<int ,int > data[12000];int dp[210][27110];int main(){ int n; scanf("%d", &n); int mem=0; int max11=0, max12=0; while(n--){ scanf("%s", str); int len=strlen(str); int val=0; for(int a=0; a<len; a++){ val+=str[a]-'a'+1; } max11=max(max11, len); max12=max(max12, val); data[mem++]=make_pair(len, val); } for(int a=1; a<=26; a++){ dp[1][a]=1; } for(int i=2; i<=max11; i++){//len for(int j=i; j<=max12; j++){//val if(dp[i][j])continue; if(j-i<=25){ dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%MOD; } else if(j-i>25){ dp[i][j]=((dp[i][j-1]-dp[i-1][j-27]+MOD)%MOD+dp[i-1][j-1])%MOD; } } } for(int a=0; a<mem; a++) printf("%d\n", ((dp[data[a].first][data[a].second]-1)+MOD)%MOD); return 0;}
阅读全文
0 0
- Cipher CodeForces
- CodeForces 156C Cipher
- Codeforces 156c Cipher
- codeforces 722F. Cyclic Cipher
- Cipher
- Cipher
- Cipher
- cipher
- 【DP】-Codeforces Round #110 (Div. 1)-C. Cipher
- codeforces 156C Cipher 组合数学 字符串dp
- Cipher Code
- 1026 Cipher
- EVP cipher
- Playfair Cipher
- 加密---Cipher
- Cipher-----置换
- Cipher(P1026)
- Ancient Cipher
- Java_面向对象02 this关键字
- Android应用层(View体系)三
- docker测试环境目录满,迁移
- [caioj 1479,利用矩阵乘法解决的经典题目一]点的变换
- Python爬取拉勾网数据存入MySql
- Cipher CodeForces
- Segment set(并查集 + 计算几何问题)
- 《图解HTTP》整理(5)
- x264编译“CommandLineToArgvW”未定义的问题
- 欢迎使用CSDN-markdown编辑器
- 二叉树建立 先序 中序 后序输出
- HDU-1754 I Hate It(线段树,区间最大值)
- Day 6-14.Comment documentation
- [java][spring]PropertyEditor