10651-pebble Solitaire
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1592
into the binary for state transfer, see Code.
Complete code:
/*0.016s*/#include <bits/stdc++.h> using namespace std;
const int Size = 12;
Char Str[size];
int dp[4100];
bitset<size> tmp;
int f (unsigned long N) {if (n = = 0 | | dp[n]) return dp[n];
Bitset<size> b (n); int minn = B.count ();///in the case of not card time, I use Bitset is because this function is very convenient, although I write a few lines///with Bitset can also avoid the trouble caused by operator precedence (!). ~ higher than << >> above = = above & above ^ above | Above && above | |
for (int i = 0; i < Size; ++i) {if (!b.test (i))///equivalent to if ((n>>i&1) ==0) { if (i < Size-2 && B.test (i + 1) && b.test (i + 2)) {TMP =
b
Tmp.set (i), tmp.reset (i + 1), Tmp.reset (i + 2),///equivalent to n|1u<<i,n&~ (1u<< (i+1)), n&~ (1u<< (i+2))
Minn = MIN (Minn, F (Tmp.to_ulong ()));
} if (i > 1 && b.test (i-1) && b.test (i-2)) { TMP = b;
Tmp.set (i), Tmp.reset (i-1), Tmp.reset (i-2);
Minn = MIN (Minn, F (Tmp.to_ulong ()));
}} return Dp[n] = Minn;
int main () {int T, I;
scanf ("%d", &t);
while (t--) {GetChar (); for (i = 0; i < Size; ++i) str[i] = (GetChar () = = '-'?
' 0 ': ' 1 ');
printf ("%d\n", F (Strtoul (str, NULL, 2));
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/