648631
1402 2012-01-14 16:16:57 Accepted 0.60 s 728 K C++ 1517 B laoyang103
数据果然很小
不会超时
哈尔滨工业大学的OJ http://acm.hit.
程序代码:
#include <stdio.h>
#include <string.h>
int answer[7];
bool foot[50];
int q(int n,int m)
{
if((n<1)||(m<1) )return 0;
if(n==1||m==1) return 1;
if(n<m) return q(n,n);
if(n==m)return q(n,m-1)+1;
return q(n,m-1)+q(n-m,m);
}
void dfs2(int n,int k,int depth,int front)
{
if(depth > k)return ;
if(0 == n)
{
if(depth == k)answer[2]++;
return ;
}
int i;
for(i = n;i;i--)
{
if(i<=front)
{
int temp = front;
front = i;
dfs2(n-i,k,depth+1,front);
front = temp;
}
}
}
void dfs4(int n,int k,int front)
{
if(0 == n)
{
answer[4]++;
return ;
}
int i;
for(i = n;i;i--)
{
if((i & 0x01) && i<=front)
{
int temp = front;
front = i;
dfs4(n-i,k,front);
front = temp;
}
}
}
void dfs5(int n,int k,int front)
{
if(0 == n)
{
answer[5]++;
return ;
}
int i;
for(i = n;i;i--)
{
if(!foot[i] && i<=front)
{
foot[i] = true;
int temp = front;
front = i;
dfs5(n-i,k,front);
front = temp;
foot[i] = false;
}
}
}
int main()
{
int n,k;
while(EOF != scanf("%d%d",&n,&k))
{
memset(answer,0,sizeof(answer));
memset(foot,0,sizeof(foot));
dfs2(n,k,0,100);
dfs4(n,k,100);
dfs5(n,k,100);
printf("%d\n",q(n,n));
printf("%d\n",answer[2]);
printf("%d\n",q(n,k));
printf("%d\n",answer[4]);
printf("%d\n\n",answer[5]);
}
return 0;
}