最近一星期状态就不是很好,也不知道为什么,很多时候连看题都看不进去,偶尔A的几道题也是强逼着自己看的总之不是一种很正常的学习状态。
这种蛋疼的状态终于在今天下午一觉睡醒之后完全消除了,我又回到了那个什么都不怕,内心极度阳光的我,GOGOGO!!!
好了,这道题真不知道别人是怎么想的。。。我直接dfs搜,别人有的用的bfs,刘汝佳还归类到dp里,算了,过了就好
//============================================================================// Name : 10651.cpp// Author :// Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================#include#include using namespace std;#define INF 1<<30string s;int d[30];int temp, ans, n;void dfs(){ int tag = 0; for(int i = 0;i < 12;i++){ if(i+2 < 12&&d[i] == 1&&d[i+1] == 1&&d[i+2] == 0){ tag = 1; d[i] = 0; d[i+1] = 0; d[i+2] = 1; dfs(); d[i+2] = 0; d[i+1] = 1; d[i] = 1; } else if(i-2 >= 0&&d[i] == 1&&d[i-1] == 1&&d[i-2] == 0){ tag = 1; d[i] = 0; d[i-1] = 0; d[i-2] = 1; dfs(); d[i] = 1; d[i-1] = 1; d[i-2] = 0; } } if(tag == 0){ temp = 0; for(int i = 0;i < 12;i++){ if(d[i] == 1) temp++; } if(ans > temp) ans = temp; } return;}int main() { freopen("a.txt", "r", stdin); scanf("%d", &n); while(n--){ cin >> s; for(int i = 0;i < 12;i++){ if(s[i] == '-') d[i] = 0; else d[i] = 1; } ans = INF; dfs(); printf("%d\n", ans); } return 0;}