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个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
随机推荐
- python+selenium安装指导
一. 安装python 1.Window 平台安装 Python 以下为在 Window 平台上安装 Python 的简单步骤: 打开 WEB 浏览器访问https://www.python ...
- Tensorflow实现LSTM识别MINIST
import tensorflow as tf import numpy as np from tensorflow.contrib import rnn from tensorflow.exampl ...
- 软工实践Alpha冲刺(8/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成非功能的主界面制作 ...
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
PS:近来有几个刚使用nginx的新童鞋老问我,nginx+fastcgi不够稳定,偶尔出现502错误,怎么解决?本人使用nginx也有3年多了,也认为php-fpm模块不够稳定,在访问量不大的时候没 ...
- dirname(__FILE__)
dirname() 函数返回路径中的目录部分. __FILE__ :被称为PHP魔术常量,返回当前执行PHP脚本的完整路径和文件名,包含一个绝对路径 dirname(__FILE__) 函数返回的是脚 ...
- LeetCode -- Construct Binary Tree from Preorder and Inorder
Question: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may as ...
- [THUWC2017][bzoj5020] 在美妙的数学王国中畅游 [LCT+泰勒展开]
题面 LOJ传送门 思路 这里很重要 它提示我们,把给定的三个函数泰勒展开,并用LCT维护每一项泰勒展开式的值,维护十几项就满足了题目的精度要求 我们考虑一个函数在0位置的泰勒展开 $f(x)=\su ...
- [bzoj] 3263 陌上花开 洛谷 P3810 三维偏序|| CDQ分治 && CDQ分治讲解
原题 定义一个点比另一个点大为当且仅当这个点的三个值分别大于等于另一个点的三个值.每比一个点大就为加一等级,求每个等级的点的数量. 显然的三维偏序问题,CDQ的板子题. CDQ分治: CDQ分治是一种 ...
- [hdu] 5696 区间的价值 || 序列分治
原题 我们定义"区间的价值"为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 求长度分别为1-n的区间的最大价值. 保证数据随机 因 ...
- POJ 3421 X-factor Chains | 数论
题意: 给一个x,求最长的排列满足开头是1,结尾是x,前一个数是后一个数的因子 输出长度和这样序列的个数 题解: 把x分解质因数,质因数个数就是答案,接下来考虑怎么求个数 显然这是一个可重集合全排列问 ...