]]>poj 2978 Colored stoneshttp://m.shnenglu.com/huicpc0860/archive/2010/05/18/115690.htmlhuicpc0860huicpc0860Tue, 18 May 2010 08:42:00 GMThttp://m.shnenglu.com/huicpc0860/archive/2010/05/18/115690.htmlhttp://m.shnenglu.com/huicpc0860/comments/115690.htmlhttp://m.shnenglu.com/huicpc0860/archive/2010/05/18/115690.html#Feedback0http://m.shnenglu.com/huicpc0860/comments/commentRss/115690.htmlhttp://m.shnenglu.com/huicpc0860/services/trackbacks/115690.html//鐘舵佸帇緙ヾp #include <stdio.h> #include <string.h> int dp[101][6][160];
int max(int a, int b) { return a > b ? a : b; }
int main() { int m, k; while (scanf("%d%d", &m, &k), m || k) { memset(dp, 0, sizeof (dp)); int n =1<< k, ans =0, a; for (int i =1; i <= m; i++) { scanf("%d", &a); a--; for (int j =0; j < k; j++) for (int s =0; s < n; s++) if ((s >> a)&1) { if (a == j) dp[i][j][s] = max(dp[i][j][s], dp[i -1][j][s] +1); else dp[i][j][s] = max(dp[i][j][s], dp[i -1][j][s]); } else { dp[i][a][s | (1<< a)] = max(dp[i][a][s | (1<< a)], dp[i -1][j][s] +1); dp[i][j][s] = max(dp[i][j][s], dp[i -1][j][s]); } } for (int i =0; i < k; i++) for (int j =0; j < n; j++) ans = max(ans, dp[m][i][j]); printf("%d\n", m - ans); } return0; }
]]>poj 2411 Mondriaan's Dreamhttp://m.shnenglu.com/huicpc0860/archive/2010/05/17/115596.htmlhuicpc0860huicpc0860Mon, 17 May 2010 08:11:00 GMThttp://m.shnenglu.com/huicpc0860/archive/2010/05/17/115596.htmlhttp://m.shnenglu.com/huicpc0860/comments/115596.htmlhttp://m.shnenglu.com/huicpc0860/archive/2010/05/17/115596.html#Feedback0http://m.shnenglu.com/huicpc0860/comments/commentRss/115596.htmlhttp://m.shnenglu.com/huicpc0860/services/trackbacks/115596.html#include <stdio.h> #include <string.h> constint N =1<<11; longlong x[N], y[N]; int n, m, t;
bool check(int x) { while (x) { if (x &1) { x >>=1; if (x &1)x >>=1; elsereturn0; } else x >>=1; } return1; }
bool judge(int now, int last) { int tmp = t & (~last); if ((now & tmp) == tmp && check(now - tmp))return1; return0; }
int main() { while (scanf("%d%d", &n, &m), n || m) { if ((n &1) && (m &1)) { puts("0"); continue; } if (n < m)n ^= m, m ^= n, n ^= m; int s =1<< m; t = s -1; for (int i =0; i < s; i++)y[i] = check(i); for (int i =1; i < n; i++) { for (int j =0; j < s; j++) for (int k =0; k < s; k++) if (judge(j, k))x[j] += y[k]; memcpy(y, x, sizeof (x[0]) * s); memset(x, 0, sizeof (x[0]) * s); } printf("%lld\n",y[t]); } return0; }