3 solutions

  • 3
    @ 2024-1-23 11:36:33

    #include #include using namespace std; int f[1001][1001]; int main() { int n,m,a,b,t; cin>>t; for(n=0;n<=10;n++) for(m=0;m<=10;m++) { f[n][m]=1; if (n0 || m1) f[n][m]=1; else if (n>=m) f[n][m]=f[n][m-1]+f[n-m][m]; else f[n][m]=f[n][n]; } while (t--) { cin>>a>>b; cout<<f[a][b]<<endl; } return 0; }

    • 1
      @ 2025-2-7 21:28:00
      #include <bits/stdc++.h>
      
      using namespace std;
      int m, n;
      int ans = 0;
      
      void dfs(int s, int a, int b) {//s:剩余苹果数量,a:盘子编号,b:前一个盘子苹果数量
      	if (a == n) {//当盘子编号为n时
      		if (s >= b) {//苹果数量为空时(剩下的苹果放第n号盘子)
      			ans++;//方案数+1
      			return ;
      		}
      	}
      	for (int i = b; i <= s; i++) {//遍历还剩下的苹果的编号(数量)
      		//s-i=下一盘可装数量,a+1=盘子数量(编号)+1,i表示当前放i个苹果
      		dfs(s - i, a + 1, i);
      	}
      }
      
      int main() {
      	int t;
      	cin >> t;
      	while (t--) {
      		cin >> m >> n;
      		//初始化:有m个苹果,第一个盘子,前一个盘子苹果数量为空
      		dfs(m, 1, 0);
      		cout << ans << '\n';
      		ans = 0;
      
      	}
      	return 0;
      }
      
      • 1
        @ 2024-1-23 11:47:08

        老师的呆马👍🎉️

        #include<bits/stdc++.h>
        using namespace std;
        long n;
        long f(long m, long n){
        	if(n > m){
        		return f(m, m);
        	}
        	if(m == 0){
        		return 1;
        	}
        	if(n <= 0){
        		return 0;
        	}
        	return f(m, n - 1) + f(m-n, n);
        	
        }
        int main(){
        	long t, m ,n;
        	cin >> t;
        	while(t--){
        		cin >> m >> n;
        		cout << f(m, n) << endl;
        	}
        	return 0;
        }
        
        • 1

        Information

        ID
        692
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        2
        Tags
        # Submissions
        47
        Accepted
        30
        Uploaded By