跳蚤
Description
Z城市居住着多只跳蚤。在很Z城市周六生活频道有一频频频目。一只跳蚤被频上一高空个将个
频频的正中央。频频频~可以看作是无限频。频目主持人频频跳蚤频一频片。片上有很会卡卡写N+1个数个自然。其中最后一是M~而前N个数都不超频M~片上允频有相同的字。跳蚤每卡数
次可以片上任意频频一自然从卡个数S~然后向左~或向右跳S个频位频度。而他最频的任频是跳到距他左频一频位频度的地方~频起位于那里的物。 离个并礼
比如当N=2~M=18频~持有片卡(10, 15, 18)的跳蚤~就可以完成任频,他可以先向左跳10个频位频度~然后再频向左跳3次~每次15个频位频度~最后再向右频跳3次~每次18个频位频度。而持有片卡(12, 15, 18)的跳蚤~频频也不可能跳到距他左频一频位频度的地方。 怎个
当确定N和M后~频然一共有M^N频不同的片。频在的频频是~在频所有的片中~有多少频卡卡
可以完成任频。
Input
两个数整N和M(N <= 15 , M <= 100000000)。
Output
可以完成任频的片。卡数
Sample Input
2 4
Sample Output
12
Hint
频12频片分频是, 卡
(1, 1, 4), (1, 2, 4), (1, 3, 4), (1, 4, 4), (2, 1, 4), (2, 3, 4),
(3, 1, 4), (3, 2, 4), (3, 3, 4), (3, 4, 4), (4, 1, 4), (4, 3, 4)
来源,
最新频频 频表频频
您尚未登频本站~不能频表频频~频登频
频频人: hanhan0121 频布频频: 2010-3-8 2:08:08
因频物在左频的一频位频~所以频每一频偶频不能拿到频物~礼个个数数并礼
频频人: davyjang 频布频频: 2010-3-4 23:22:08
#include"stdio.h"
#include"math.h"
int m=0,n=0,c[1000]={NULL},position=0,count_can=0;
bool jump(int x[])
{
int temp1[1000]={NULL},temp2[1000]={NULL};
for(int i=0;x[i]!=NULL;i++)
{
if(x[i]==1)
return(true);
temp1[i]=x[i];
}
int l=1,s=0;
do{
s=0;
if(l==1)
{
for(int i=0;temp1[i]!=NULL;i++)
{
for(int j=i+1;temp1[j]!=NULL;j++)
{
if(fabs(temp1[i]-temp1[j])==1)
{
return(true);
}
if(temp1[i]-temp1[j]!=0)
{
temp2[s]=(int)fabs(temp1[i]-temp1[j]);
s++;
}
}
temp1[i]=0;
}
l=2;
}
else
{
for(int i=0;temp2[i]!=NULL;i++)
{
for(int j=i+1;temp2[j]!=NULL;j++)
{
if(fabs(temp2[i]-temp2[j])==1)
{
return(true);
}
if(temp2[i]-temp2[j]!=0)
{
temp1[s]=(int)fabs(temp2[i]-temp2[j]);
s++;
}
}
temp2[i]=0;
}
l=1;
}
}while(s!=0);return(false);}
void card(int depth){
if(depth==m)
{
c[m]=n;
if(jump(c)==true)
{
count_can++;
}
return;
}
else
{
for(int i=1;i<=n;i++)
{
c[depth]=i;
depth++;
card(depth);
depth--;
}
return;
}
}
void main()
{
scanf("%d%d",&m,&n);card(0);
printf("%d\n",count_can);
}