2 条题解

  • 0
    @ 2025-10-8 16:56:32
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 4002;
    const long long mod = 2147483648;
    int n;
    long long f[N];//保险起见,防止爆 int 
    int main() {//f_i : 数 i 拆分为任意个数相加的形式的方案总数
    	ios::sync_with_stdio(0); //关闭同步流
    	cin.tie(0), cout.tie(0); //等待时间设为零
    	f[0] = 1; //注意将 f_0 初始化为 1 
    	cin >> n;
    	for (int i = 1; i <= n; i++) //枚举拆分数 
    		for (int j = i; j <= n; j++) //枚举被拆分数 
    			f[j] = (f[j] + f[j - i]) % mod; //状态转移 
    	cout << f[n] - 1;//记得除去本身 
    	return 0;
    }
    
    • 0
      @ 2025-10-8 16:56:26
      #include <bits/stdc++.h>
      using namespace std;
      const int N = 4002;
      const long long mod = 2147483648;
      int n;
      long long f[N];//保险起见,防止爆 int 
      int main() {//f_i : 数 i 拆分为任意个数相加的形式的方案总数
      	ios::sync_with_stdio(0); //关闭同步流
      	cin.tie(0), cout.tie(0); //等待时间设为零
      	f[0] = 1; //注意将 f_0 初始化为 1 
      	cin >> n;
      	for (int i = 1; i <= n; i++) //枚举拆分数 
      		for (int j = i; j <= n; j++) //枚举被拆分数 
      			f[j] = (f[j] + f[j - i]) % mod; //状态转移 
      	cout << f[n] - 1;//记得除去本身 
      	return 0;
      }
      
      • 1

      (已测)0x50 动态规划(0x52 背包)例题2:正整数拆分

      信息

      ID
      1366
      时间
      1000ms
      内存
      64MiB
      难度
      3
      标签
      递交数
      83
      已通过
      43
      上传者