记录编号 345152 评测结果 AAAAAAAAAA
题目名称 [USACO 1.5.4] 跳棋的挑战 最终得分 100
用户昵称 Gravatarrewine 是否通过 通过
代码语言 C++ 运行时间 1.967 s
提交时间 2016-11-10 20:33:23 内存使用 0.14 MiB
显示代码纯文本
#define pro __attribute__((optimize("O3")))
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>
#include <bitset>
 
using namespace std;
#define FRE(name) freopen(#name".in","r",stdin);freopen(#name".out","w",stdout);
typedef long long lg;

namespace PROIO{
	const int L=1<<15;
	char chout[9000],*pout=chout;
	char buf[L],*s = buf,*t = buf;
	pro inline char getc() {
		if(s==t) t=(s=buf)+fread(buf,1,L,stdin);
		if(s==t) return EOF;
		return *s++;
	}
    pro inline int read() {
	    register bool flag = 0;register char c;
		register int x;
	    while((c=getc())>'9'||c<'0') {
		  if(c == '-') flag = 1;
		  else if(c == EOF) return 0;
	    }
	    x = c-'0';
	    while((c=getc())<='9'&&c>='0')
	      x = ((x<<1)+(x<<3))+c-'0';
	    return flag ? -x : x;
    }
    pro inline void out(int x) {
        if(!x)*pout++='0';
        int p=0;char buft[10];
        while(x) buft[++p]=x%10+'0',x/=10;
        while(p) *pout++=buft[p--];
        *pout++='\n';
    }
    pro void end(){fwrite(chout,1,pout-chout,stdout);} 
}using PROIO::read;using PROIO::out;using PROIO::end;
 
#define Rep(i, x, y) for (register int i = (x), _ = (y); i <= _; i++)
#define lb(x) (x&-x) 

int li,n,ans = 0;
int f[20];

pro inline int count(int x) {
	int ans = 0;
	while(x)x >>= 1,ans++;
	return ans;
}

void dfs(int k,int l,int r,int t) {
	if(k == n+1) {
		ans++;
		if(ans <= 3) {
		  for(int i = 1;i <= n; i++)
		    printf("%d ",f[i]);
		  putchar('\n');
		}
		return;
	}
	int tmp = (~(l|r|t))&li;
	while(tmp) {
		int lo = lb(tmp);
		if(ans < 3)f[k] = count(lo);
		dfs(k+1,(l|lo)<<1,(r|lo)>>1,t|lo);
		tmp -= lo;
	}
}

pro int work() {
    FRE(checker);
    n = read();
    li = (1<<n)-1;
    dfs(1,0,0,0);
    printf("%d",ans);
}
 
int dott = work();

int main(){;}