题意:

给出长为n的字符串,含有前k种小写字母,求两个不含重复元素的连续子串,使得他们的长度乘积最大。

思路:

字符种类16 ->(套路) 状压

暴力2000*2000得所有连续子串的长度,得每个状态的最优;

dp使得包含字符个数最优。

利用异或取反得最大值。

#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1<<16;
char s[2010];
int dp[N];
int n,k; void init()
{
int val;
memset(dp,0,sizeof(dp));
for(int i=0; i<n; i++)
{
val=0;
for(int j=i; j<n; j++)
{
val|=(1<<(s[j]-'a'));
dp[val]=max(dp[val],j-i+1);
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
scanf("%s",s);
init();
for(int i=0; i<(1<<k); i++)
for(int j=0; j<k; j++)
if(i&(1<<j))
dp[i]=max(dp[i],dp[i^(1<<j)]);
int ans=0;
for(int i=0; i<(1<<k); i++)
ans=max(dp[i]*dp[((1<<k)-1)^i],ans);
printf("%d\n",ans);
}
return 0;
}

FZU 2218【状压】的更多相关文章

  1. FZU 1025 状压dp 摆砖块

    云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 ...

  2. FZU - 2218 Simple String Problem 状压dp

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

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

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

  4. fzu2188 状压dp

    G - Simple String Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  5. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  6. 【BZOJ-4197】寿司晚宴 状压DP

    4197: [Noi2015]寿司晚宴 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 694  Solved: 440[Submit][Status] ...

  7. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  8. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  9. [NOIP2016]愤怒的小鸟 D2 T3 状压DP

    [NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...

随机推荐

  1. 百度小程序转换微信小程序

    Python脚本,一键转换Github地址:https://github.com/DWmelon/py-transfer-BdToWx 运行条件 具备Python环境,可在命令行中使用Python命令 ...

  2. ajax实时获取下拉数据

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ajax ...

  3. .net 调用SAP RFC的几种方法

    转自:http://www.cherpservice.com/pub/newsdetail.asp?Newsid=3613 第一种方式采用SAP.net Connector: 最新版本是3.,不开源, ...

  4. 转换(旋转)transform

    div { transform:rotate(180deg); -ms-transform:rotate(180deg); /* IE 9 */ -moz-transform:rotate(180de ...

  5. opencv操作相机相关函数

    1.基本操作 capture = cv2.VideoCapture(0) ret, image = capture.read() cv2.imwrite("photo.jpg", ...

  6. Java for LeetCode 130 Surrounded Regions

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...

  7. Other Linker flags 添加 -Objc导致包冲突

    Other Linker flags 添加 -Objc导致包冲突 先尝试不添加-Objc,不行的话尝试下面的方法. 第三方冲突解决办法: https://www.jianshu.com/p/02846 ...

  8. LeetCode:访问所有节点的最短路径【847】

    LeetCode:访问所有节点的最短路径[847] 题目描述 给出 graph 为有 N 个节点(编号为 0, 1, 2, ..., N-1)的无向连通图. graph.length = N,且只有节 ...

  9. HTML5颜色渐变3D文字特效

    在线演示 本地下载

  10. jQuery+CSS3动画相册特效

    在线演示 本地下载