A-A
https://vjudge.net/contest/638765#problem/A
一开始贪心做不出来,后面发现是dp找到转移方程即可,01dp问题
代码如下
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
ll v[10000010];
ll n;
ll ans;
ll prefix[10000010];
int main() {
int N;
cin >> N;
vector<int> T(N);
for (int i = 0; i < N; ++i) {
cin >> T[i];
}
int all = accumulate(T.begin(), T.end(), 0);
vector<bool> dp(all / 2 + 1, false);
dp[0] = true;
for (int i = 0; i < N; ++i) {
for (int j = all / 2; j >= T[i]; --j) {
if (dp[j - T[i]]) {
dp[j] = true;
}
}
}
int result = all;
for (int i = all / 2; i >= 0; --i) {
if (dp[i]) {
result = all - i;
break;
}
}
cout << result << endl;
return 0;
}
B-B
代码如下
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
ll n;
ll ans;
ll prefix[10000010];
set<ll>st;
struct Point {
ll x, y;
};
bool dfs(ll u, vector<vector<ll>> &adj, vector<bool> &visited, vector<ll> &match) {
for (int v : adj[u]) {
if (!visited[v]) {
visited[v] = true;
if (match[v] == -1 || dfs(match[v], adj, visited, match)) {
match[v] = u;
return true;
}
}
}
return false;
}
int maxMatching(vector<vector<ll>> &adj, int n) {
vector<ll> match(n, -1);
ll count = 0;
for (int u = 0; u < n; ++u) {
vector<bool> visited(n, false);
if (dfs(u, adj, visited, match)) {
count++;
}
}
return count;
}
int main() {
int N;
cin >> N;
vector<Point> red(N);
vector<Point> blue(N);
vector<vector<ll>> adj(N);
for (int i = 0; i < N; ++i) {
cin >> red[i].x >> red[i].y;
}
for (int i = 0; i < N; ++i) {
cin >> blue[i].x >> blue[i].y;
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (red[i].x < blue[j].x && red[i].y < blue[j].y) {
adj[i].push_back(j);
}
}
}
ll result = maxMatching(adj, N);
cout << result << endl;
return 0;
}
H-H
https://vjudge.net/contest/638765#problem/H
签到题,不多说
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
ll v[10000010];
ll n;
ll ans;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll x,y,n;
cin>>x>>y>>n;
if(3*x<=y){
cout<<n*x;
}else {
if(n>=3){
cout<<(n/3)*y+(n%3)*x;
}else
cout<<n*x;
}
}
其他题正在补。。。。。。
D-D
https://vjudge.net/contest/638765#problem/D
F-F
https://vjudge.net/contest/638765#problem/F
标签:zhaosang,int,ll,2024,++,vector,友谊赛,adj,match From: https://www.cnblogs.com/dontian/p/18301933