We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1fd6c28 commit 70f8fdbCopy full SHA for 70f8fdb
CSES/Removing Digits.cpp
@@ -0,0 +1,29 @@
1
+#include<bits/stdc++.h>
2
+
3
+using namespace std;
4
5
+#define int long long
6
+#define M 1000000007
7
+#define N 300010
8
9
+signed main(){
10
11
+ ios_base::sync_with_stdio(false);
12
+ cin.tie(NULL);
13
14
+ int n;
15
+ cin >> n;
16
+ int dp[n+1];
17
+ for(int i=0;i<=n;i++)
18
+ dp[i]=INT_MAX;
19
+ dp[0]=0;
20
+ for(int i=1;i<=n;i++){
21
+ int num=i;
22
+ while(num>0){
23
+ int val=num%10;
24
+ num/=10;
25
+ dp[i]=min(dp[i],dp[i-val]+1);
26
+ }
27
28
+ cout << dp[n] << endl;
29
+}
0 commit comments