FZU-2218 Simple String Problem(状态压缩DP)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#define eps 1e-12
using namespace std;
typedef long long ll;
const ll mo = 1000000007, N = 2*1e3+10;
char s[N];
int dp[(1<<16)+100];
int main()
{
int t;
cin>>t;
while(t--)
{
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s);
memset(dp, 0, sizeof(dp));
for(int i = 0; i<n; i++)
{
int t = 0;
for(int j = i; j<n; j++)
{
t |= 1<<(s[j] - 'a');
dp[t] = max(dp[t], j - i + 1);
}
}
int s = 1<<m;
for(int i = 0; i<s; i++)
{
for(int j = 0; j<m; j++)
{
if((1<<j) & i)
dp[i] = max(dp[i], dp[i^(1<<j)]);
}
}
int ans = 0;
for(int i = 0; i<s; i++)
{
ans = max(ans, dp[i]*dp[(s-1)^i]);
}
cout<<ans<<endl;
}
return 0;
}
FZU-2218 Simple String Problem(状态压缩DP)的更多相关文章
- FZU - 2218 Simple String Problem 状压dp
FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- FZU 2218 Simple String Problem(简单字符串问题)
Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...
- Codeforces C. A Simple Task(状态压缩dp)
题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- POJ 3691 (AC自动机+状态压缩DP)
题目链接: http://poj.org/problem?id=3691 题目大意:给定N个致病DNA片段以及一个最终DNA片段.问最终DNA片段最少修改多少个字符,使得不包含任一致病DNA. 解题 ...
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 4057 AC自己主动机+状态压缩dp
http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...
- 状态压缩dp(hdu2167,poj2411)
hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
随机推荐
- iOS笔记060 - 自定义控件
自定义tabBar 系统自带的tabBar不能满足需求 自己定义UITabBar 自定义一个类继承自UITabBar 实现initWithFrame和layoutSubviews方法即可. //#im ...
- Git上手:Git扫盲区
Git 自述Git 是由伟大的电脑程序员Linus Torvalds编写的一个开源的,分布式的版本控制系统软件. Git 核心原理Git 利用底层数据结构,通过指向索引对象的可变指针,保存文件快照. ...
- springboot整合jersey
https://blog.csdn.net/xiongpei00/article/details/76576420
- 【转载】全面解析Unity3D自动生成的脚本工程文件
我们在Unity3D开发的时候,经常会看到它会产生不少固定命名工程文件,诸如: Assembly-CSharp-vs.csproj Assembly-CSharp-firstpass-vs.csp ...
- super和final关键字
一.super关键字 super关键字的使用 JAVA类中使用super来引用父类的属性或者方法,用this来引用当前对象,主要用法: 1.子类的构造函数默认第一行会默认调用父类的无参数构造函数 2. ...
- jquery实现各种实例
1.正反选实例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- GridView与ListView冲突
由于GridView与listView都是继承自ScrollView,所以两个控件放在一起时需要重写控件方法 public class MyGridView extends GridView{ ...
- favicon.ico generator
favicon.ico generator https://www.favicon-generator.org/ https://www.favicon.cc/ https://www.favicon ...
- Android应用如何打包?
android app开发结束后,就需要对app进行打包.部署与发布了,那对于android初学者而言,如何对apk进行打包呢?今天小编就为大家分享一二,一起来看看吧~~ aapt package - ...
- BZOJ3244 [Noi2013]树的计数 【数学期望 + 树遍历】
题目链接 BZOJ3244 题解 不会做orz 我们要挖掘出\(bfs\)序和\(dfs\)序的性质 ①容易知道\(bfs\)序一定是一层一层的,如果我们能确定在\(bfs\)序中各层的断点,就能确定 ...