1 solutions

  • 0
    @ 2025-3-22 10:47:32
    #include<bits/stdc++.h>
    using namespace std;
    const int N=15;
    int f[N][N]; //f[i][j]表示将i分成j个数的方案数
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int m,n;
            cin>>m>>n;
            memset(f,0,sizeof 0);
            f[0][0]=1;
            for(int i=0;i<=m;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    f[i][j]=f[i][j-1];//至少有一个空盘子
                    if(i>=j)
                    {
                        f[i][j]+=f[i-j][j];//一个空盘子都没有
                    }
                }
            }
            cout<<f[m][n]<<endl;
        }
    }
    • @ 2025-3-22 10:48:00
      #include<bits/stdc++.h>
      using namespace std;
      int dfs(int x,int y)
      {
      	if(x==0) return 1;//没有苹果盘子都是空的
      	if(y==0) return 0;//没有苹果,没有办法分
      	if(y>x) //盘子数目大于苹果数目,最多使用x个盘子来放 
      	{
      		return dfs(x,x); 
      	}
      	return dfs(x-y,y)+dfs(x,y-1);
      	//     没有空盘子,至少一个空盘子 
      }
      int main()
      {
      	int t,n,m;
      	cin>>t;
      	while(t--)
      	{
      		cin>>n>>m;
      		cout<<dfs(n,m)<<endl;	
      	}	
      	return 0;
      }

Information

ID
1438
Time
1000ms
Memory
128MiB
Difficulty
5
Tags
(None)
# Submissions
19
Accepted
4
Uploaded By