-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aae42f8
commit 0efd098
Showing
17 changed files
with
22,892 additions
and
3,414 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
myCpps_2020/blobsInTheBoard_UVA11391/blobsInTheBoard_UVA11391.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("blobsInTheBoard_UVA11391.in"); | ||
ofstream fout("blobsInTheBoard_UVA11391.out"); | ||
|
||
using ll = long long; | ||
|
||
const ll maxC = 16; | ||
|
||
ll vtoi(vector<vector<ll>> & a) | ||
{ | ||
ll ny = a.size(), nx = a[0].size(), ans = 0; | ||
for (ll y = 0; y <= ny - 1; ++y) | ||
{ | ||
for (ll x = 0; x <= nx - 1; ++x) | ||
{ | ||
if (a[y][x] == 1) | ||
{ | ||
ll c = y * nx + x; | ||
|
||
ans += (1 << c); | ||
--c; | ||
} | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
vector<vector<ll>> itov(ll x, ll ny, ll nx) | ||
{ | ||
ll c = ny * nx - 1; | ||
bitset<maxC> b(x); | ||
|
||
vector<vector<ll>> a(ny, vector<ll>(nx, 0)); | ||
for (ll i = 0; i <= c; ++i) | ||
{ | ||
a[i / nx][i % nx] = b[i]; | ||
} | ||
|
||
return a; | ||
} | ||
|
||
bool inside(ll y, ll x, ll ny, ll nx) | ||
{ | ||
return y >= 0 && y <= ny - 1 && x >= 0 && x <= nx - 1; | ||
} | ||
|
||
int main() | ||
{ | ||
vector<ll> py = {-1, -1, 0, 1, 1, 1, 0, -1}, | ||
px = {0, 1, 1, 1, 0, -1, -1, -1}; | ||
|
||
ll tcc; fin >> tcc; | ||
for (ll t = 1; t <= tcc; ++t) | ||
{ | ||
ll ny, nx, nb; fin >> ny >> nx >> nb; | ||
vector<vector<ll>> s(ny, vector<ll>(nx, 0)); | ||
for (ll c = 1; c <= nb; ++c) | ||
{ | ||
ll y, x; fin >> y >> x; | ||
--y; --x; | ||
s[y][x] = 1; | ||
} | ||
|
||
ll c = ny * nx, s_i = vtoi(s); | ||
vector<ll> dp((1 << c), 0); dp[s_i] = 1; | ||
vector<ll> now, next; now.push_back(s_i); | ||
|
||
for (ll cb = nb; cb > 1; --cb) | ||
{ | ||
vector<ll> next_exist((1 << c), 0); | ||
|
||
ll size = now.size(); | ||
for (ll i = 0; i <= size - 1; ++i) | ||
{ | ||
ll nowX = now[i]; | ||
|
||
if (dp[nowX] > 0) | ||
{ | ||
vector<vector<ll>> now = itov(nowX, ny, nx); | ||
for (ll y = 0; y <= ny - 1; ++y) | ||
{ | ||
for (ll x = 0; x <= nx - 1; ++x) | ||
{ | ||
if (now[y][x] == 1) | ||
{ | ||
for (ll p = 0; p <= 8 - 1; ++p) | ||
{ | ||
ll sty = y + py[p], stx = x + px[p], | ||
ty = y + py[p] * 2, tx = x + px[p] * 2; | ||
|
||
if (inside(sty, stx, ny, nx) == true && inside(ty, tx, ny, nx) == true) | ||
{ | ||
if (now[sty][stx] == 1 && now[ty][tx] == 0) | ||
{ | ||
now[y][x] = 0; now[sty][stx] = 0; now[ty][tx] = 1; | ||
|
||
ll now_i = vtoi(now); | ||
dp[now_i] += dp[nowX]; | ||
if (next_exist[now_i] == 0) | ||
{ | ||
next.push_back(now_i); | ||
next_exist[now_i] = 1; | ||
} | ||
|
||
now[y][x] = 1; now[sty][stx] = 1; now[ty][tx] = 0; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
now = next; | ||
next.clear(); | ||
} | ||
|
||
// for (ll nowX = 0; nowX <= (1 << c) - 1; ++nowX) | ||
// { | ||
// if (dp[nowX] > 0) | ||
// { | ||
// vector<vector<ll>> now = itov(nowX, ny, nx); | ||
// for (ll y = 0; y <= ny - 1; ++y) | ||
// { | ||
// for (ll x = 0; x <= nx - 1; ++x) | ||
// { | ||
// fout << now[y][x]; | ||
// } | ||
// fout << '\n'; | ||
// } | ||
// fout << dp[nowX] << "\n\n"; | ||
// } | ||
// } | ||
|
||
ll ans = 0; | ||
for (ll i = 0; i <= c; ++i) | ||
{ | ||
ll nowX = (1 << i); | ||
if (nowX > (1 << c) - 1) break; | ||
|
||
ans += dp[nowX]; | ||
} | ||
|
||
fout << "Case " << t << ": " << ans << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.