题意:
给你一个串和两个整数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. CSS系列(7)CSS类选择器Class详解

    这一篇文章,以笔记形式写. 1,  CSS 类选择器详解 http://www.w3school.com.cn/css/css_selector_class.asp 知识点: (1)    使用类选择 ...

  2. 融合模型Aggregation

    从一堆弱分类器融合得到强分类器. 比如假设现在你只能水平或竖直线分割,那么无论如何都分不好,但是假设组合三次分割,就会得到如图所示的一个较好的分割线. 再比如,PLA 融合后有large margin ...

  3. 微信小程序--背景图片手机无法预览

    目前小程序好像没有支持手机预览背景本地图片,所以将本地图片改为网络图片链接就可以了 background: url("https://..../img/no.png") no-re ...

  4. InfluxDB安装后web页面无法访问的解决方案

    本文属于<InfluxDB系列教程>文章系列,该系列共包括以下 16 部分: InfluxDB学习之InfluxDB的安装和简介 InfluxDB学习之InfluxDB的基本概念 Infl ...

  5. 在Struts等框架中获取Spring容器的方式

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(ServletContext src); ...

  6. [洛谷P4389]付公主的背包

    题目大意:有$n(n\leqslant10^5)$种物品,第$i$个物品体积为$v_i$,都有$10^5$件.给定$m(m\leqslant10^5)$,对于$s\in [1,m]$,请你回答用这些商 ...

  7. [hdu6434]Problem I. Count

    题目大意:$T(T\leqslant 10^5)$组数据,每组数据给你$n(n\leqslant 2\times 10^7)$,求$\sum\limits_{i=1}^n\sum\limits_{j= ...

  8. JZOJ 5280 膜法师

    好啰嗦......还好作者给了一句话题意,不然光看题就很耗费时间. 样例输入: 1 6 3 1 78 69 55 102 233 666 样例输出: 1 2 3 4 5 6 11  数据范围: 思路: ...

  9. POJ 1236 Networks of School Tarjan 基础

    题目大意: 给一个有向图,一个文件可以从某个点出发传递向他能连的边 现在有两个问题 1.至少需要多少个放文件可以让整个图都有文件 2.可以进行一个操作:给一对点(u,v)连一条u->v的有向边, ...

  10. bzoj4772 显而易见的数论

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=4772 sol :这个题卡了我一整天QAQ 出题人简直丧心病狂,卡内存+卡常数QAQ 题意就是, ...