【LOJ #6397】【THUPC2018】—蛋糕 / Cake(DFS)

传送门

初始假设每个点都是8个面
考虑每一维ii,最上下2个i1i-1维多边形肯定是减少一个被染色
剩下len[i]2len[i]-2个多边形减少2个被染色的面

搜一下就完了
特判一下len[i]=1len[i]=1的情况

#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0,f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
#define re register
#define pb push_back
#define cs const
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
cs ll mod=2148473648;
inline void chemx(ll &a,ll b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
cs int N=15;
ll ans[N],len[N];
void dfs(int dim,ll coef,int m){
	if(dim==0){
		(ans[m]+=coef)%=mod;
		return;
	}
	if(len[dim]==1){
		dfs(dim-1,coef,m);
		return;
	}
	dfs(dim-1,coef*2%mod,m-1);
	dfs(dim-1,coef*(len[dim]-2)%mod,m-2);
}
int main(){
	int T=read();
	while(T--){
		len[1]=read(),len[2]=read(),len[3]=read(),len[4]=read();
		memset(ans,0,sizeof(ans));
		dfs(4,1,8);
		for(int i=0;i<=8;i++)cout<<ans[i]<<" ";puts("");
	}
}
posted @ 2019-08-01 21:39  Stargazer_cykoi  阅读(118)  评论(0编辑  收藏  举报