题意:
给你一个串和两个整数n和k,n表示串的长度,k表示串只有前k个小写字母,问你两个不含相同元素的连续子串的长度的最大乘积。
思路:
状态压缩DP最多16位,第i位的状态表示第i位字母是否存在,
代码:
#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)的更多相关文章

  1. FZU - 2218 Simple String Problem 状压dp

    FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...

  2. FZU - 2218 Simple String Problem(状压dp)

    Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...

  3. FZU 2218 Simple String Problem(简单字符串问题)

    Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...

  4. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  6. POJ 3691 (AC自动机+状态压缩DP)

    题目链接:  http://poj.org/problem?id=3691 题目大意:给定N个致病DNA片段以及一个最终DNA片段.问最终DNA片段最少修改多少个字符,使得不包含任一致病DNA. 解题 ...

  7. hdu4336 Card Collector 状态压缩dp

    Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. hdu 4057 AC自己主动机+状态压缩dp

    http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...

  9. 状态压缩dp(hdu2167,poj2411)

    hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...

随机推荐

  1. 【Balanced Binary Tree】cpp

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  2. 一个关于pynoi游戏的C语言编程

    "去吧,秦,好好享受这个夜晚,我给你准备了一份礼物,希望你能喜欢."小布莱克眨着眼睛笑道,狡猾的像一头小狐狸.

  3. install.cloudinit.qga.bat

    @echo off title Auto Install color 1F ::CloudBase-Init echo. msiexec /i \\192.168.122.47\cloudbase\C ...

  4. 用Python实现基于Hadoop Stream的mapreduce任务

    用Python实现基于Hadoop Stream的mapreduce任务 因为Hadoop Stream的存在,使得任何支持读写标准数据流的编程语言实现map和reduce操作成为了可能. 为了方便测 ...

  5. Python编码报错

    Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息:SyntaxErr ...

  6. hexo从零开始到搭建完整 转

    http://visugar.com/2017/05/04/20170504SetUpHexoBlog/ https://liuchi.coding.me/   look me 交流群 有相关问题的可 ...

  7. [Codeforces 1027 F] Session in BSU [并查集维护二分图匹配问题]

    题面 传送门 思路 真是一道神奇的题目呢 题目本身可以转化为二分图匹配问题,要求右半部分选择的点的最大编号最小的一组完美匹配 注意到这里左边半部分有一个性质:每个点恰好连出两条边到右半部分 那么我们可 ...

  8. [CTSC2017][bzoj4903] 吉夫特 [状压dp+Lucas定理]

    题面 传送门 思路 一句话题意: 给出一个长度为 n 的序列,求所有长度大于等于2的子序列个数,满足:对于子序列中任意两个相邻的数 a和 b (b 在 a 前面),$C_a^b mod 2=1$,答案 ...

  9. 公路建设 (highway.c/cpp/pas)

    2.公路建设 (highway.c/cpp/pas) 在滨海市一共有 n 个城市,编号依次为 1 到 n,它们之间计划修建 m 条双向道路,其中 修建第 i 条道路的费用为 ci. 海霸王作为滨海市公 ...

  10. 【CF edu 27 G. Shortest Path Problem?】

    time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...