some dp problems

This commit is contained in:
2024-06-14 19:49:10 +02:00
parent 66d059f230
commit b67bf7bbea
21 changed files with 124 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
// Removing Digits
#include<bits/stdc++.h>
using namespace std;
int dp[(int)1e6 + 1];
int solve(int n) {
if (dp[n]) return dp[n];
int count = INT_MAX;
if (n == 0) return 0;
for (int i = 1; i <= 10 * n; i*= 10) {
int remove = (n / i) - (n / (10 * i)) * 10;
if (!remove) continue;
count = min(count, 1 + solve(n - remove));
}
dp[n] = count;
return count;
}
int main() {
int n; cin >> n;
cout << solve(n) << endl;
return 0;
}