25 条题解
-
0paca LV 8 @ 2009-10-03 11:17:59
如何优化?老超时~~
program vijos_t1050_4;
var n,m,i,j:longint;
b,a:array[0..2001]of longint;
p:array[1..2001]of boolean;function find(h,k:longint):boolean;
var i,j:longint;
begin
find:=false;
i:=0;
for j:=1 to h-1 do
if a[j]b[h] then exit;
end;
if k -
02009-10-02 17:42:14@
有这么多人了……
太邪恶了! -
02009-10-02 15:45:12@
占位
顺便orz -
02009-10-02 15:10:22@
踩场……
-
-22016-12-09 13:53:01@
#include<cstdio>
#include<cstring>
#define maxa 2100
int a[maxa],n,b[maxa],c[maxa],tot = 0;
void dfs(int cur)
{
int i,j;
if(cur>n+1)
return ;
if(cur==n+1)
{
tot++;
return ;
}
else
for(i=1;i<=n;++i)
if(c[i]==0)
{
int msg =0;
a[cur] =i;
for(j=1;j<=cur;++j)
if(a[j]<=cur)
msg++;
if(msg==b[cur])
{
c[i]= 1;
dfs(cur+1);
c[i] = 0;
}
}
}
int main()
{
int i;
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%d",&(b[i]));
dfs(1);
printf("%d\n",tot);
return 0;
}