Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴个c++代码 h=10,w=11时答案是3852472573499#include <iostream> using namespace std; long long dp[2][2048]; int main() { int h, w; long long res; bool n; while (true) { cin >> h >> w; if (!h) { break; } n = false; for (int i = 0; i < 2048; i++) { dp[0][i] = 0; dp[1][i] = 0; } dp[n][0] = 1; for (int i = h - 1; i >= 0; i--) { for (int j = w - 1; j >= 0; j--) { for (int u = 0; u < (1 << w); u++) { res = 0; if ((u >> j) & true) { res = dp[n][u & (~(1 << j))]; } else { if (j + 1 < w && !((u >> (j + 1)) & true)) { res += dp[n][u | (1 << (j + 1))]; } if (i + 1 < h) { res += dp[n][u | (1 << j)]; } } dp[!n][u] = res; } n = !n; } } cout << dp[n][0] << '\n'; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator