Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Oct 1, 2019
1 parent aae42f8 commit 0efd098
Show file tree
Hide file tree
Showing 17 changed files with 22,892 additions and 3,414 deletions.
16,076 changes: 12,913 additions & 3,163 deletions myCpps/password.in

Large diffs are not rendered by default.

1,250 changes: 1,000 additions & 250 deletions myCpps/password.out

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions myCpps_2020/blobsInTheBoard_UVA11391/blobsInTheBoard_UVA11391.cpp
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;
}
Loading

0 comments on commit 0efd098

Please sign in to comment.