http://www.bnuoj.com/bnuoj/problem_show.php?pid=29036
用集合保存已经走过的状态。
代码:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#define maxn 22
#define ll long long
using namespace std;
ll f[maxn]={0,1,2,4,10,32,122,544,
2770LL,
15872LL,
101042LL,
707584LL,
5405530LL,
44736512LL,
398721962LL,
3807514624LL,
38783024290LL,
419730685952LL,
4809759350882LL,
58177770225664LL,
740742376475050LL,
};
//ll DP()
//{
// memset(dp,0,sizeof(dp));
// for(int i=0; i<n; i++)
// {
// dp[1<<i][i][0]=dp[1<<i][i][1]=1;
// }
cout<<"yes"<<endl;
// for(int i=1; i<(1<<n); i++)
// {
// for(int j=0; j<n; j++)
// {
cout<<i<<' '<<j<<endl;
// for(int k=0; k<j; k++) //k<j
// {
// if((i&(1<<k))&&(i&(1<<j)))
// {
// dp[i][j][0]+=dp[i^(1<<j)][k][1];
// }
// }
// for(int k=j+1; k<n; k++) //k>j
// {
// if(i&(1<<k)&&(i&(1<<j)))
// {
// dp[i][j][1]+=dp[i^(1<<j)][k][0];
// }
// }
cout<<i<<' '<<j<<endl;
// }
// }
cout<<"yes"<<endl;
// ll ans=0;
// for(int i=0; i<n; i++)
// {
// ans+=dp[(1<<n)-1][i][0];
// ans+=dp[(1<<n)-1][i][1];
// }
// return ans;
//}
int main()
{
// freopen("C:\\Users\\lhq\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\lhq\\Desktop\\out.txt","w",stdout);
int t;
scanf("%d",&t);
for(int i=1; i<=t; i++)
{
int num,n;
scanf("%d%d",&num,&n);
// scanf("%d%d",&num,&n);
printf("%d %lld\n",num,f[n]);
}
return 0;
}