题目链接:Click here

Solution:

状压dp,考虑\(f[i][j][k]\)表示当前到了第i个石头,颜色状态为j,选取的最后一个石头颜色为k时能够留下的石头的最大数量

转移也很好转移,枚举所有状态,再枚举上次转移过来的状态的最后一个颜色,然后暴力转移就行了

最后查找一下所有情况下的最大值,输出n-max就行了

Code:

#include<cstdio>
#include<ctype.h>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,f[101][(1<<8)-1][7];
int b[7]={0,1};
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main(){
for(int i=2;i<=6;i++) b[i]=b[i-1]*2;
begin:n=read(),m=read();
if(n==0&&m==0) return 0;
memset(f,0,sizeof(f));
int num=b[m+1]-1,ans=0;
for(int i=1;i<=n;i++){
int x=read();
for(int s=0;s<=num;s++){
if(!(s&b[x]))
for(int j=1;j<=m;j++){
if(!(s&b[j])) continue;
f[i][s|b[x]][x]=max(f[i][s|b[x]][x],f[i-1][s][j]+1);
f[i][s][j]=max(f[i][s][j],f[i-1][s][j]);
}
else
for(int j=1;j<=m;j++){
if(j==x) f[i][s][x]=max(f[i][s][x],f[i-1][s][j]+1);
else if(s&b[j]) f[i][s][j]=max(f[i][s][j],f[i-1][s][j]);
}
}
}
for(int i=1;i<=m;i++)
for(int s=0;s<=num;s++)
if(s&b[i]) ans=max(ans,f[n][s][i]);
printf("%d\n",n-ans);goto begin;
}

Pku2978 Colored stones的更多相关文章

  1. HOJ 2156 &POJ 2978 Colored stones(线性动规)

    Colored stones Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1759 Accepted: 829 Descrip ...

  2. [poj 2978]Colored Stones[状态压缩DP]

    题意: 给出n个石子,一共m种颜色.问最少去掉几个石子使得同种颜色全连续. 思路见注释. #include <algorithm> #include <cstdio> #inc ...

  3. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  4. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  5. HDU 5973 Game of Taking Stones 威佐夫博弈+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...

  6. POJ 2513 Colored Sticks

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 28036   Accepted: 7428 ...

  7. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

  8. 周赛-Colored Sticks 分类: 比赛 2015-08-02 09:33 7人阅读 评论(0) 收藏

    Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 32423 Accepted: 8556 Desc ...

  9. codeforces 553A . Kyoya and Colored Balls 组合数学

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

随机推荐

  1. v-if 和v-show的区别

    在切换 v-if 块时,Vue.js 有一个局部编译/卸载过程,因为 v-if 之中的模板也可能包括数据绑定或子组件.v-if 是真实的条件渲染,因为它会确保条件块在切换当中合适地销毁与重建条件块内的 ...

  2. pair常见用法

    pair的使用 关于pair 什么是pair 可以将pair看做一个内部有两个元素的结构体,且两个元素的类型是可以指定的. struct pair{ typename1 first; typename ...

  3. [POI2011]SMI-Garbage 题解

    题面 想必各位大佬一定想到了把现在和目标值不一致的边加入到一个新建的图上: 问题就变为了在新的图上寻找有多少个欧拉回路,并输出这些路径: 我们可以用栈来记录情况,然后对于会回答稍微处理处理就好了: # ...

  4. Java Web开发技术教程入门-初识动态网页

    这段时间学校搞了一个"阅战阅勇"的阅读活动,奖品还是挺丰富的~于是,奔着这些奖品,我去图书馆借了这本<Java Web开发技术教程>.一是为了那些丰富的奖品,二是为了回 ...

  5. ArcGIS 在VS2010中 ESRI.ArcGIS.SOESupport.dll 无法正常加载的处理

    转自  http://blog.csdn.net/tnt123688/article/details/23186973 问题描述: 打开ArcGIS的SOE模板后,提示  错误 命名空间“ESRI.A ...

  6. 097、如何实现Service伸缩?(Swarm04)

    参考https://www.cnblogs.com/CloudMan6/p/7885667.html   上一节部署了只有一个副本的Service,不过对于web服务,我们通常会运行多个实例,这样可以 ...

  7. 【转载】jquery版的网页倒计时效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 关于KMeans和range的使用

    #!/usr/bin/python#-*-coding:utf-8-*-import numpy as npfrom sklearn.cluster import KMeansfrom scipy.s ...

  9. HTML-简单动画

    简单动画 (1)简单动画通常称之为“过渡transition” Transition-property:需要过渡的属性,但是并非所有的属性都支持过渡. Transition-duration:过渡的时 ...

  10. 009-saltstack之salt-ssh的使用及配置管理LAMP状态的实现

    1.salt-ssh的使用 官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html (1)安装salt-ssh [root@l ...