mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-22 03:01:43 +00:00
将变量类型从 int 更改为 ll,以支持更大的数值范围
This commit is contained in:
parent
44bf9e3531
commit
217e981c00
@ -1,44 +1,47 @@
|
|||||||
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using ll = int64_t;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ios::sync_with_stdio(false);
|
ios::sync_with_stdio(false);
|
||||||
cin.tie(0);
|
cin.tie(0);
|
||||||
|
|
||||||
int n, m, k;
|
ll n, m, k;
|
||||||
cin >> n >> m >> k;
|
cin >> n >> m >> k;
|
||||||
vector<string> v(n);
|
vector<string> v(n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (ll i = 0; i < n; i++) {
|
||||||
cin >> v[i];
|
cin >> v[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> dp(k + 1, 1e9);
|
vector<ll> dp(k + 1, 1e9);
|
||||||
dp[0] = 0;
|
dp[0] = 0;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (ll i = 0; i < n; i++) {
|
||||||
vector<int> a;
|
vector<ll> a;
|
||||||
for (int j = 0; j < m; j++) {
|
for (ll j = 0; j < m; j++) {
|
||||||
if (v[i][j] == '1') {
|
if (v[i][j] == '1') {
|
||||||
a.push_back(j);
|
a.push_back(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int p = a.size();
|
ll p = a.size();
|
||||||
vector<int> f(p + 1, 0);
|
vector<ll> f(p + 1, 0);
|
||||||
|
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
vector<int> ndp = dp;
|
vector<ll> ndp = dp;
|
||||||
dp = move(ndp);
|
dp = move(ndp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
f[p] = 0;
|
f[p] = 0;
|
||||||
for (int t = 0; t < p; t++) {
|
for (ll t = 0; t < p; t++) {
|
||||||
int b = p - 1 - t;
|
ll b = p - 1 - t;
|
||||||
int mval = 1e9;
|
ll mval = 1e9;
|
||||||
for (int x = 0; x <= t; x++) {
|
for (ll x = 0; x <= t; x++) {
|
||||||
int cost = a[b + x] - a[x] + 1;
|
ll cost = a[b + x] - a[x] + 1;
|
||||||
if (cost < mval) {
|
if (cost < mval) {
|
||||||
mval = cost;
|
mval = cost;
|
||||||
}
|
}
|
||||||
@ -46,9 +49,9 @@ int main() {
|
|||||||
f[t] = mval;
|
f[t] = mval;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> ndp(k + 1, 1e9);
|
vector<ll> ndp(k + 1, 1e9);
|
||||||
for (int j = 0; j <= k; j++) {
|
for (ll j = 0; j <= k; j++) {
|
||||||
for (int t = 0; t <= min(p, j); t++) {
|
for (ll t = 0; t <= min(p, j); t++) {
|
||||||
if (dp[j - t] != 1e9) {
|
if (dp[j - t] != 1e9) {
|
||||||
if (dp[j - t] + f[t] < ndp[j]) {
|
if (dp[j - t] + f[t] < ndp[j]) {
|
||||||
ndp[j] = dp[j - t] + f[t];
|
ndp[j] = dp[j - t] + f[t];
|
||||||
@ -59,7 +62,7 @@ int main() {
|
|||||||
dp = move(ndp);
|
dp = move(ndp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ans = *min_element(dp.begin(), dp.end());
|
ll ans = *min_element(dp.begin(), dp.end());
|
||||||
cout << ans << endl;
|
cout << ans << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user