Pku2978 Colored stones
题目链接: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的更多相关文章
- HOJ 2156 &POJ 2978 Colored stones(线性动规)
Colored stones Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1759 Accepted: 829 Descrip ...
- [poj 2978]Colored Stones[状态压缩DP]
题意: 给出n个石子,一共m种颜色.问最少去掉几个石子使得同种颜色全连续. 思路见注释. #include <algorithm> #include <cstdio> #inc ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- poj 2513 Colored Sticks trie树+欧拉图+并查集
点击打开链接 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27955 Accepted ...
- HDU 5973 Game of Taking Stones 威佐夫博弈+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...
- POJ 2513 Colored Sticks
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 28036 Accepted: 7428 ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- 周赛-Colored Sticks 分类: 比赛 2015-08-02 09:33 7人阅读 评论(0) 收藏
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 32423 Accepted: 8556 Desc ...
- 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 ...
随机推荐
- 第五周课程总结&实验报告(三)
实验三 String类的应用 实验目的: (1)掌握类String类的使用: (2)学会使用JDK帮助文档: 实验内容: 1.已知字符串:"this is a test of java&qu ...
- tableau desktop
参考: 入门指南: https://help.tableau.com/current/guides/get-started-tutorial/zh-cn/get-started-tutorial-co ...
- mysql-5.7.25安装以及使用
1. wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 2. ...
- luogu P3210 [HNOI2010]取石头游戏
传送门 不会结论做个鬼系列 题意其实是在头尾(最多)两个栈以及中间一些双端队列依次取数,然后每个人都要最大化自己的价值 有一个结论,如果一段序列中,出现了三个相邻位置\(A,B,C\),满足\(A\l ...
- oracle的基本情况和一些基本概念
Oracle Database,又名Oracle RDBMS,或简称Oracle.是甲骨文公司的一款关系数据库管理系统.它是在数据库领域一直处于领先地位的产品.可以说Oracle数据库系统是目前世界上 ...
- 使用redis客户端连接windows和linux下的redis并解决无法连接redis的问题
搭建环境:linux是centos7.4(请注意centos7以下版本的防火墙跟centos7以上的不同,使用redis客户端连接redis时会有区别,建议使用centos7以上版本) 一.下载red ...
- oracle使用between and边界问题
如果是只查询某两个月之间的数据,会默认从每个月的1号开始查,包前包后 eg:select * from test_hsj where regdate between to_date('2015-05' ...
- redis数据库到mysql或mongodb数据库
# -*- coding:utf-8 -*-# item_mongodb.py import redis import pymongo import json def main(): redis_co ...
- linux 读取文本的最后几行
tail -n 100 filename 读取file的最后100行 tail: n. 尾巴:踪迹:辫子:燕尾服 vt. 尾随:装上尾巴 vi. 跟踪:变少或缩小 adj. 从后面而来的:尾部的 ...
- 最简单的Android项目
这是我在windows环境下,试验过的最简单Android项目,只用记事本和命令行即可完成. 环境准备 开发环境需要Java SDK(官网下载),Android SDK(官网下载). 首先安装Java ...