- 数的划分
- 2014-11-06 19:06:52 @
#include <iostream>
using namespace std;
int a[10],n,k,ans;
int right()
{
int flag,s;
flag=0;
s=0;
for (int i=1;i<=k;i++)
s=s+a[i];
if (s==n) flag=1;
return flag;
}
void dfs(int deep,int last)
{
int tot;
for (a[deep]=last;a[deep]<=n;a[deep]++)
{
if (deep==k )
{
if (right()==1) ans++;
}
else dfs(deep+1,a[deep]);
}
return;
}
int main()
{
a[0]=-1000;
cin>>n>>k;
dfs(1,1);
cout<<ans;
}
3 条评论
-
绿杖白牛 LV 7 @ 2014-11-08 15:49:11
这ID是不是很吊?
-
2014-11-06 19:36:48@
orz
-
2014-11-06 19:19:53@
LZSB
- 1