标签:style blog color io for div sp log on
dfs+剪枝*4(通过得很勉强):
#include<cstdio> using namespace std; const int f[]={3,1,0,0}; int n,a[9],ans,Pre[9]; void dfs(int x,int y) { if(Pre[x]>a[x])return; if(Pre[x]+(n-y+1)*3<a[x])return; if(x==n){ans++;return;} if(y==n) { int tmp=a[x]-Pre[x]; if(tmp==2)return; Pre[y]+=f[tmp]; dfs(x+1,x+2); Pre[y]-=f[tmp]; }else{ Pre[x]+=3;dfs(x,y+1);Pre[x]-=3; Pre[y]+=3;dfs(x,y+1);Pre[y]-=3; Pre[x]++;Pre[y]++;dfs(x,y+1);Pre[x]--;Pre[y]--;} } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); dfs(1,2); printf("%d\n",ans); return 0; }
【搜索】【剪枝】bzoj1306 [CQOI2009]match循环赛
标签:style blog color io for div sp log on
原文地址:http://www.cnblogs.com/autsky-jadek/p/3959466.html