码迷,mamicode.com
首页 > 其他好文 > 详细

atcoder CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

时间:2017-11-03 22:03:57      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:二进制   normal   bcd   stand   print   sel   display   数字   ica   

Problem Statement

We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s1s2sNfrom left to right. (Here, s=s1+s2+…+sN holds.) Snuke wants to satisfy the following condition:

  • For each i (1≤iN), it is possible to permute the characters in si and obtain a palindrome.

Find the minimum possible value of N when the partition satisfies the condition.

 

用二进制记下前缀的每种字母奇偶性

dp[i]表示前i个最少分几段,枚举奇数字母是什么转移

可以记下每种二进制最小的dp值是什么

 

技术分享
#include<bits/stdc++.h>  
using namespace std;
char s[200005];
int f[1<<26];
int main(){
    scanf("%s",&s);
    int n=strlen(s),td;
    for (int i=1;i<(1<<26);i++) f[i]=1000000000;
    for (int i=0,zt=0;i<n;i++){
        zt^=(1<<(s[i]-a));
        td=f[zt]+1;
        for (int j=0;j<26;j++) td=min(td,f[zt^(1<<j)]+1);
        f[zt]=min(f[zt],td);
    }
    printf("%d",td);
}
View Code

 

 

 


Time limit : 3sec / Memory limit : 512MB

Score : 700 points

Problem Statement

We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s1s2sNfrom left to right. (Here, s=s1+s2+…+sN holds.) Snuke wants to satisfy the following condition:

  • For each i (1≤iN), it is possible to permute the characters in si and obtain a palindrome.

Find the minimum possible value of N when the partition satisfies the condition.

Constraints

  • 1≤|s|≤2×105
  • s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum possible value of N when the partition satisfies the condition.


Sample Input 1

Copy
aabxyyzz

Sample Output 1

Copy
2

The solution is to partition s as aabxyyzz = aab + xyyzz. Here, aab can be permuted to form a palindrome aba, and xyyzz can be permuted to form a palindrome zyxyz.


Sample Input 2

Copy
byebye

Sample Output 2

Copy
1

byebye can be permuted to form a palindrome byeeyb.


Sample Input 3

Copy
abcdefghijklmnopqrstuvwxyz

Sample Output 3

Copy
26

Sample Input 4

Copy
abcabcxabcx

Sample Output 4

Copy
3

The solution is to partition s as abcabcxabcx = a + b + cabcxabcx.

atcoder CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

标签:二进制   normal   bcd   stand   print   sel   display   数字   ica   

原文地址:http://www.cnblogs.com/lengtouqing/p/7780281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!