描述

Clickomania is a puzzle in which one starts with a rectangular grid of cells of different colours. In each step, a player selects ("clicks") a cell. All connected cells of the same colour as the selected cell (including itself) are removed if the selected cell is connected to at least one other cell of the same colour. The resulting "hole" is filled in by adjacent cells based on some rule, and the object of the game is to remove all cells in the grid. In this problem, we are interested in the one-dimensional version of the problem. The starting point of the puzzle is a string of colours (each represented by an uppercase letter).
At any point, one may select (click) a letter provided that the same letter occurs before or after the one selected. The substring of the same letter containing the selected letter is removed, and the string is shortened to remove the hole created. To solve the puzzle, the player has to remove all letters and obtain the empty string. If the player obtains a non-empty string in which no letter can be selected, then the player loses. For example, if one starts with the string "ABBAABBAAB", selecting the first "B" gives "AAABBAAB". Next, selecting the last "A" gives "AAABBB". Selecting an "A" followed by a "B" gives the empty string. On the other hand, if one selects the third "B" first, the string "ABBAAAAB" is obtained. One may verify that regardless of the next selections, we obtain either the string "A" or the string "B" in which no letter can be selected. Thus, one must be careful in the sequence of selections chosen in order to solve a puzzle. Furthermore,
there are some puzzles that cannot be solved regardless of the choice of selections. For example, "ABBAAAAB" is not a solvable puzzle. Some facts are known about solvable puzzles: The empty string is solvable. If x and y are solvable puzzles, so are xy, AxA, and AxAyA for any uppercase letter
A. All other puzzles not covered by the rules above are unsolvable.
Given a puzzle, your task is to determine whether it can be solved or not.

输入

Each case of input is specified by a single line. Each line contains a string of uppercase letters. Each string has at least one but no more than 150 characters. The input is terminated by the end of file.

输出

For each input case, print solvable on a single line if there is a sequence of selections that solves the puzzle. Otherwise, print unsolvable on a line.

样例输入

ABBAABBAAB
ABBAAAAB

样例输出

solvable
unsolvable

题目大意:

每次去掉一段字符相同(两个以上)的去掉,问最后能不能去完。

dp[i][j]代表区间[i,j]能不能去完。然后就是讨论AxA,AA,AxAyA,xy几种情况。

#include <bits/stdc++.h>
using namespace std;
char s[];
int dp[][];
int main()
{
while(~scanf("%s",s+))
{
memset(dp,,sizeof dp);
int len=strlen(s+);
for(int l=;l<=len;l++)
{
for(int i=;i+l<=len;i++)
{
int j=i+l;
if(s[i]==s[j])
{
if(dp[i+][j-]||l==)///AxA||AA
dp[i][j]=;
for(int k=i;k<=j;k++)///AxAyA
if(s[i]==s[k])
if((k-<i+||dp[i+][k-])&&(k+>j-||dp[k+][j-]))///AAyA||AxAA||AAA
dp[i][j]=;
}
for(int k=i;k<=j;k++)///xy
if(dp[i][k]&&dp[k+][j]) dp[i][j]=;
}
}
if(dp[][len]) printf("solvable\n");
else printf("unsolvable\n");
}
return ;
}

最新文章

  1. Eclipse CDT “Symbol NULL could not be resolved”
  2. file标签选择文件change事件失效处理方法
  3. DuckHunter Attacks
  4. CSS 3中边框怎么用
  5. NSHTTPCookie类详解
  6. linux中grep使用方法具体解释
  7. 深入理解学习Git工作流(转)
  8. 时间戳 获得当前时间 -iOS
  9. 两种构造 String 的方法效率比较
  10. Unity Socket UDP
  11. Python:bs4的使用
  12. Ajax获取Response头信息
  13. 火狐l浏览器所有版本
  14. 使用Windows命令行启动关闭服务(net,sc用法)
  15. Python机器学习笔记:利用Keras进行分类预测
  16. JavaScript之加载表格、表单行数据[插件]
  17. 微信小程序 - 支持html空格(提示)
  18. e816. 创建工具栏
  19. ios开发 学习积累20161027~20161031
  20. 【洛谷P1265】公路修建

热门文章

  1. JS中数组的介绍
  2. PHP识别二维码功能,php-zbarcode 安装
  3. vertx从入门到精通
  4. labview密码忘记怎么办,如何破解labview密码,vi密码md5码破解重置
  5. 迅为iMX6Q/PLUS开发板烧写设备树内核 Qt 系统
  6. WPF中做出一个QQ登陆界面
  7. urlrrtrieve()实例_下载微博短视频
  8. DatePicker 注意点 1.不用v-model 用:value 2.配合on-change进行回调 3.初始值 当天的用 (new Date()).toLocaleDateString().replace(/\//g, &#39;-&#39;)
  9. python_110_反射
  10. CPP-基础:关于引用