竞赛
考级
法兰西玫瑰
#include <bits/stdc++.h> using namespace std; int arr[105],n; int ans = INT_MAX; void dfs(int x,int son1,int son2){ if (x == n){ ans = (ans < abs(son1 - son2)) ? ans : abs(son1 - son2); return; } dfs(x + 1,son1 + arr[x],son2); dfs(x + 1,son1,son2 + arr[x]); return; } int main(){ cin >> n; for (int i = 0;i < n;i++) cin >> arr[i]; dfs(0,0,0); cout << ans; }
鹰子
途中还出了一个笑话: 你能找到不同吗?
dchk-SY
废话不多说,直接上代码
唱跳坤
#include<bits/stdc++.h> using namespace std; int max_jz,jiazhi[10005],n,dp[10005],mmax; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>jiazhi[i],max_jz+=jiazhi[i]; mmax=max_jz; max_jz/=2; for(int i=1;i<=n;i++) for(int j=max_jz;j>=jiazhi[i];j--) dp[j]=max(dp[j-jiazhi[i]]+jiazhi[i],dp[j]); cout<<mmax-2*dp[max_jz]; return 0; }
༺ཌༀ我要上浙大ༀད༻
#include <bits/stdc++.h> using namespace std; int arr[115],n; int ans = INT_MAX; void dfs(int x,int sonone,int sontwo){ if (x == n){ ans = (ans < abs(sonone - sontwo)) ? ans : abs(sonone - sontwo); return; } dfs(x + 1,sonone + arr[x],sontwo); dfs(x + 1,sonone,sontwo + arr[x]); return; } int main(){ cin >> n; for (int i = 0;i < n;i++) cin >> arr[i]; dfs(0,0,0); cout << ans; }
西伯利亚种土豆
准
#include <bits/stdc++.h> using namespace std; int arr[115],n; int ans = INT_MAX; void dfs(int x,int sonone,int sontwo){ if (x == n){ ans = (ans < abs(sonone - sontwo)) ? ans : abs(sonone - sontwo); return; } dfs(x + 1,sonone + arr[x],sontwo); dfs(x + 1,sonone,sontwo + arr[x]); return; } int main(){ cin >> n; for (int i = 0;i < n;i++) cin >> arr[i]; dfs(0,0,0); cout << ans; return 0; }
菜
风中雪zLyXj
耐高总冠军 张文杰
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int total_sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; total_sum += a[i]; } int half = total_sum / 2; vector<vector<bool>> dp(n + 1, vector<bool>(half + 1, false)); dp[0][0] = true; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= half; ++j) { if (j < a[i-1]) { dp[i][j] = dp[i-1][j]; } else { dp[i][j] = dp[i-1][j] || dp[i-1][j - a[i-1]]; } } } int max_sum = 0; for (int j = half; j >= 0; --j) { if (dp[n][j]) { max_sum = j; break; } } cout << total_sum - 2 * max_sum << endl; return 0; }
「完全なる黄金の回転エネルギー」
提交答案之后,这里将显示提交结果~