# uva10884 Persephone

• 每一列占据的格子一定是一段区间；
• 相邻列之间的区间有交。
• 上界先增后减，下界先减后增。

$f_{i,j,k,0/1,0/1}$表示考虑前$i$列，第$i$列，上界为$j$下界为$k$且上界正在上升/下降，下界正在上升/下降的方案数。转移请自行YY。

#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

const int maxn = 60,ten[4] = {1,10,100,1000},maxl = 12;
int N;
struct BigNumber
{
int d[maxl];

inline BigNumber(const string &s)
{
memset(d,0,sizeof d);
int len = s.size(),i,j,k; d[0] = (len-1)/4+1;
for (i = 1;i < maxl;++i) d[i] = 0;
for (i = len-1;i >= 0;--i)
{
j = (len-i-1)/4+1,k = (len-i-1)%4;
d[j] += ten[k]*(s[i]-'0');
}
while (d[0] > 1&& !d[d[0]]) --d[0];
}

inline BigNumber() { *this = BigNumber(string("0")); }

inline string toString() const
{
string s(""); int i,j,temp;
for (i = 3;i >= 1;--i) if (d[d[0]] >= ten[i]) break;
temp = d[d[0]];
for (j = i;j >= 0;--j) s += (char)(temp/ten[j]+'0'),temp %= ten[j];
for (i = d[0]-1;i;--i)
{
temp = d[i];
for (j = 3;j >= 0;--j) s += (char)(temp/ten[j]+'0'),temp %= ten[j];
}
return s;
}

friend inline BigNumber operator +(const BigNumber &a,const BigNumber &b)
{
BigNumber c; int x = 0; c.d[0] = max(a.d[0],b.d[0]);
for (int i = 1;i <= c.d[0];++i) x += a.d[i]+b.d[i],c.d[i] = x % 10000,x /= 10000;
while (x) c.d[++c.d[0]] = x % 10000,x /= 10000;
return c;
}

friend inline bool operator ==(const BigNumber &a,const BigNumber &b)
{
if (a.d[0] != b.d[0]) return false;
for (int i = 1;i <= a.d[0];++i) if (a.d[i] != b.d[i]) return false;
return true;
}
}f[maxn][maxn][maxn][2][2],ans[maxn*2];

{
for (int r = 1;r <= 25;++r)
{
if (r == 2)
{
int u; ++u;
}
int c = 50-r;
for (int i = 1;i <= r;++i)
for (int j = i;j <= r;++j)
{
f[1][i][j][0][0] = BigNumber(string("1"));
f[1][i][j][0][1] = f[1][i][j][1][0] = f[1][i][j][1][1] = BigNumber();
if (i == 1) f[1][i][j][1][0] = BigNumber(string("1"));
if (j == r) f[1][i][j][0][1] = BigNumber(string("1"));
if (i == 1&&j == r) f[1][i][j][1][1] = BigNumber(string("1"));
}
for (int i = 2;i <= c;++i)
for (int j = 1;j <= r;++j)
for (int k = j;k <= r;++k)
{
f[i][j][k][0][0] = f[i][j][k][0][1] = f[i][j][k][1][0] = f[i][j][k][1][1] = BigNumber();
for (int jj = 1;jj <= r;++jj)
for (int kk = jj;kk <= r;++kk)
{
if (jj > k||kk < j) continue;
if (jj >= j)
{
if (kk <= k) f[i][j][k][0][0] = f[i-1][jj][kk][0][0]+f[i][j][k][0][0];
if (kk >= k&&k != r) f[i][j][k][0][1] = f[i-1][jj][kk][0][1]+f[i][j][k][0][1];
}
if (jj <= j&&j != 1)
{
if (kk <= k) f[i][j][k][1][0] = f[i][j][k][1][0]+f[i-1][jj][kk][1][0];
if (kk >= k&&k != r) f[i][j][k][1][1] = f[i][j][k][1][1]+f[i-1][jj][kk][1][1];
}
}
if (j == 1&&k == r)
{
f[i][j][k][1][1] = f[i][j][k][0][0];
f[i][j][k][0][1] = f[i][j][k][0][0];
f[i][j][k][1][0] = f[i][j][k][0][0];
}
else if (j == 1) f[i][j][k][1][0] = f[i][j][k][0][0],f[i][j][k][1][1] = f[i][j][k][0][1];
else if (k == r) f[i][j][k][0][1] = f[i][j][k][0][0],f[i][j][k][1][1] = f[i][j][k][1][0];
}
for (c = r;c <= 49;++c)
{
if (r+c > 50) continue;
for (int i = 1;i <= r;++i)
for (int j = i;j <= r;++j)
{
ans[(r+c)<<1] = ans[(r+c)<<1]+f[c][i][j][1][1];
if (c != r) ans[(r+c)<<1] = ans[(r+c)<<1]+f[c][i][j][1][1];
}
}
}
}

int main()
{
freopen("10884.in","r",stdin);
freopen("table.out","w",stdout);
printf("ans[101]={");
for (int i = 0;i <= 100;++i)
{
if (i) putchar(',');
cout << "string(\""<<ans[i].toString() << "\")";
}
putchar('}');
fclose(stdin); fclose(stdout);
return 0;
}


#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

int N,T;
string ans[101]={string("0"),string("0"),string("0"),string("0"),string("1"),string("0"),string("2"),string("0"),string("7"),string("0"),string("28"),string("0"),string("120"),string("0"),string("528"),string("0"),string("2344"),string("0"),string("10416"),string("0"),string("46160"),string("0"),string("203680"),string("0"),string("894312"),string("0"),string("3907056"),string("0"),string("16986352"),string("0"),string("73512288"),string("0"),string("316786960"),string("0"),string("1359763168"),string("0"),string("5815457184"),string("0"),string("24788842304"),string("0"),string("105340982248"),string("0"),string("446389242480"),string("0"),string("1886695382192"),string("0"),string("7955156287456"),string("0"),string("33468262290096"),string("0"),string("140516110684832"),string("0"),string("588832418973280"),string("0"),string("2463133441338048"),string("0"),string("10286493304041104"),string("0"),string("42892130604098656"),string("0"),string("178592047539343200"),string("0"),string("742609229473744320"),string("0"),string("3083957343567791392"),string("0"),string("12792021060576424896"),string("0"),string("53000868925259947840"),string("0"),string("219365134324873522816"),string("0"),string("907023528883142832360"),string("0"),string("3746790354386182679408"),string("0"),string("15463645062002474062384"),string("0"),string("63767018378178067474656"),string("0"),string("262742756317344213209200"),string("0"),string("1081765434874991509707040"),string("0"),string("4450606984357021640248032"),string("0"),string("18298022787758605020282816"),string("0"),string("75179913955330333724697136"),string("0"),string("308691924054843201409922592"),string("0"),string("1266737680502193374869298720"),string("0"),string("5195143014579351011947302208"),string("0"),string("21294548056433354780482923744"),string("0"),string("87238762619153966026251258944"),string("0"),string("357215388993130669706869321408")};

int main()
{
freopen("10884.in","r",stdin);
freopen("10884.out","w",stdout);
scanf("%d",&T);
for (int Case = 1;Case <= T;++Case)
{
printf("Case #%d: ",Case); scanf("%d",&N);
cout << ans[N] << endl;
}
fclose(stdin); fclose(stdout);
return 0;
}

posted @ 2017-02-15 23:26  lmxyy  阅读(291)  评论(0编辑  收藏  举报