Light oj 1025 (区间dp)
2015-09-07 11:57
357 查看
1025 - The Specials Menu
Feuzem is an unemployed computer scientist who spends his days working at odd-jobs. While on the job he always manages to find algorithmic problems within mundane aspects of everyday life.
Today, while writing down the specials menu at the restaurant he's working at, he felt irritated by the lack of palindromes (strings which stay the same when reversed) on the menu. Feuzem is a big fan of palindromic problems, and started thinking about the
number of ways he could remove letters from a particular word so that it would become a palindrome.
Two ways that differ due to order of removing letters are considered the same. And it can also be the case that no letters have to be removed to form a palindrome.
Each case contains a single word W (1 ≤ length(W) ≤ 60).
PROBLEM SETTER: MUNTASIR MUZAHID CHOWDHURY
SPECIAL THANKS: JANE ALAM JAN (DATASET)
题意:删除字母使得串为回文串的方案数
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
Today, while writing down the specials menu at the restaurant he's working at, he felt irritated by the lack of palindromes (strings which stay the same when reversed) on the menu. Feuzem is a big fan of palindromic problems, and started thinking about the
number of ways he could remove letters from a particular word so that it would become a palindrome.
Two ways that differ due to order of removing letters are considered the same. And it can also be the case that no letters have to be removed to form a palindrome.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.Each case contains a single word W (1 ≤ length(W) ≤ 60).
Output
For each case, print the case number and the total number of ways to remove letters from W such that it becomes a palindrome.Sample Input | Output for Sample Input |
3 SALADS PASTA YUMMY | Case 1: 15 Case 2: 8 Case 3: 11 |
SPECIAL THANKS: JANE ALAM JAN (DATASET)
题意:删除字母使得串为回文串的方案数
/* 题目链接: http://lightoj.com/volume_showproblem.php?problem=1025 */ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<set> #include<map> #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-8 typedef long long ll; using namespace std; #define N 65 ll dp ; char c ; int main() { int i,j,t,ca=0; scanf("%d",&t); while(t--) { scanf("%s",c); int len=strlen(c); memset(dp,0,sizeof(dp)); for(int i=0;i<len;i++) dp[i][i]=1; for(int i=len-1;i>=0;i--) for(int j=i+1;j<len;j++) { dp[i][j]=dp[i][i]+dp[i+1][j]; for(int k=i+1;k<=j;k++) if(c[i]==c[k]) dp[i][j]+=dp[i+1][k-1]+1; } printf("Case %d: %lld\n",++ca,dp[0][len-1]); } return 0; }
相关文章推荐
- IDEA+jetty配置jndi数据源
- R语言入门学习
- Scala总结
- SQL Server 删除作业Job (亲自实践)
- 办公室英语1
- warning : json_decode(): option JSON_BIGINT_AS_STRING not implemented in xxx
- 架构之路(二):性能
- 解决:Jersey搭建webService报错:com.sun.jersey.spi.inject.Errors$ErrorMessagesException
- YII 1.0 缓存使用
- 在Debian 8纯命令行安装android开发环境方法
- LeetCode || Permutations
- MySQL 语句级避免重复插入—— Insert Select Not Exist
- 办公室英语2
- ubuntu 12.04 tomcat + jsp的入门
- 随手写了一段C++访问LDAP, 并且获取sid的代码
- mac idea 快捷键
- BaseAdapter里面处理单击事件
- Meteor全栈开发平台 - 不仅仅是前端
- hive删除表失败
- Spring--开篇 (spring优缺点、模块组件、各个jar包详解)