1825:【01NOIP提高组】数的划分

#include<bits/stdc++.h>
using namespace std;
int n,k,a[15],tot;
void dfs(int num,int pos)
{
    if(pos==k) 
     if(num>=a[pos-1]) 
     {
         tot++;
         return;
     }
     for(int i=a[pos-1];i<=num&&num/(k-pos)>=i;i++)
     {
         a[pos]=i;
         dfs(num-i,pos+1);
         a[pos]=0;
     }
}
int main()
{
    a[0]=1;
    cin>>n>>k;
    dfs(n,1);
    cout<<tot;
    return 0;
}

因为不允许有空的,所以要定义a[0]=1,这样的话最小的一份就可以从一开始

那个整天对着电脑屏幕皮肤还贼差的大佬还是强的( ⊙ o ⊙ )!

原文地址:https://www.cnblogs.com/smartljy/p/11727011.html