将变量类型从 int 更改为 ll,以支持更大的数值范围

This commit is contained in:
Zengtudor 2025-07-23 10:43:43 +08:00
parent 44bf9e3531
commit 217e981c00

View File

@ -1,44 +1,47 @@
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
using ll = int64_t;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
ll n, m, k;
cin >> n >> m >> k;
vector<string> v(n);
for (int i = 0; i < n; i++) {
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> dp(k + 1, 1e9);
vector<ll> dp(k + 1, 1e9);
dp[0] = 0;
for (int i = 0; i < n; i++) {
vector<int> a;
for (int j = 0; j < m; j++) {
for (ll i = 0; i < n; i++) {
vector<ll> a;
for (ll j = 0; j < m; j++) {
if (v[i][j] == '1') {
a.push_back(j);
}
}
int p = a.size();
vector<int> f(p + 1, 0);
ll p = a.size();
vector<ll> f(p + 1, 0);
if (p == 0) {
vector<int> ndp = dp;
vector<ll> ndp = dp;
dp = move(ndp);
continue;
}
f[p] = 0;
for (int t = 0; t < p; t++) {
int b = p - 1 - t;
int mval = 1e9;
for (int x = 0; x <= t; x++) {
int cost = a[b + x] - a[x] + 1;
for (ll t = 0; t < p; t++) {
ll b = p - 1 - t;
ll mval = 1e9;
for (ll x = 0; x <= t; x++) {
ll cost = a[b + x] - a[x] + 1;
if (cost < mval) {
mval = cost;
}
@ -46,9 +49,9 @@ int main() {
f[t] = mval;
}
vector<int> ndp(k + 1, 1e9);
for (int j = 0; j <= k; j++) {
for (int t = 0; t <= min(p, j); t++) {
vector<ll> ndp(k + 1, 1e9);
for (ll j = 0; j <= k; j++) {
for (ll t = 0; t <= min(p, j); t++) {
if (dp[j - t] != 1e9) {
if (dp[j - t] + f[t] < ndp[j]) {
ndp[j] = dp[j - t] + f[t];
@ -59,7 +62,7 @@ int main() {
dp = move(ndp);
}
int ans = *min_element(dp.begin(), dp.end());
ll ans = *min_element(dp.begin(), dp.end());
cout << ans << endl;
return 0;