lightoj 1025 - The Specials Menu 【区间dp】
来源:互联网 发布:ios 可变字典添加数据 编辑:程序博客网 时间:2024/05/21 19:47
题目链接:lightoj 1025 - The Specials Menu
1025 - The Specials Menu
PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB
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.
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
PROBLEM SETTER: MUNTASIR MUZAHID CHOWDHURY
SPECIAL THANKS: JANE ALAM JAN (DATASET)
题意:求区间回文子序列。。。
思路:明显的区间dp。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <map>#define ll o<<1#define rr o<<1|1#define fi first#define se second#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;typedef pair<int, int> pii;const int INF = 0x3f3f3f3f;const int MAXN = 3*1e5 + 10;LL dp[100][100];char str[100];LL DFS(int i, int j) { if(i > j) return dp[i][j] = 0; if(dp[i][j] != -1) return dp[i][j]; if(i == j) return dp[i][j] = 1; LL ans = DFS(i+1, j) + DFS(i, j-1); if(str[i] == str[j]) ans += 1; else ans -= DFS(i+1, j-1); dp[i][j] = ans; return ans;}int main(){ int t, kcase = 1; scanf("%d", &t); while(t--) { scanf("%s", str+1); int len = strlen(str+1); CLR(dp, -1); printf("Case %d: %lld\n", kcase++, DFS(1, len)); } return 0;}
- LightOJ 1025 - The Specials Menu(区间DP)
- LightOJ 1025 - The Specials Menu【区间DP】
- lightoj 1025-The Specials Menu 区间DP
- lightoj 1025 - The Specials Menu 【区间dp】
- [区间DP] The Specials Menu LightOJ
- LightOJ - 1025 The Specials Menu(区间DP)
- LightOJ 1025 - The Specials Menu (区间dp)
- LightOJ 1025 The Specials Menu(区间dp)
- lightoj 1025 The Specials Menu (DP)
- LightOJ 1025 - The Specials Menu(dp)
- lightoj 1025 The Specials Menu (dp)
- LightOJ 1025 - The Specials Menu
- Light OJ 1025 The Specials Menu(区间DP)
- Light OJ 1025 The Specials Menu (区间DP)
- LightOJ1025-The Specials Menu-区间dp
- The Specials Menu 基础区间 dp
- Light OJ 1025 The Specials Menu 详细题解(回文串的区间DP)
- lightoj 1025【区间DP】
- Java基础--并发编程基础(1)
- [SpringBoot实践]spring-data-mongo自定义Repository接口及其实现
- android 开发 时间的计算问题
- 25
- linux下的redis+spring集群整合(七)
- lightoj 1025 - The Specials Menu 【区间dp】
- Linux进程调度——schedule()函数分析
- java中文乱码解决之道(五)-----java是如何编码解码的
- poj题目分类
- P网 虚拟币评分
- 大数加法A+B
- Intent的常用Flag参数
- java中文乱码解决之道(六)-----javaWeb中的编码解码
- 查询每个用户最新的日志访问信息