pre>
code>
};
}
return ans;
}
ans += ret;
long long ret = getCnt(cnt, n);
}
cnt[c-'0']++;
for(char c : vals){
int cnt[10] = {0};
for(auto vals : s){
long long ans = 0;
makePalindrome(n, k, 0, 0);
long long countGoodIntegers(int n, int k) {
}
return ret;
}
n -= cnt[i];
}
ret *= combi(n, cnt[i]);
} else{
ret *= combi(n-1, cnt[i]);
if(i == 0){
if(cnt[i] == 0) continue;
for(int i = 0 ; i < 10; i++){
long long ret = 1;
long long getCnt(int cnt[10], int n){
}
return ret;
}<= i;
ret code>
for(int i = 1; i <= r; i++){
}
n--;
rr--;
ret *= n;
while(rr){
int rr = r;
long long ret = 1;
long long combi(int n, int r){
}
}
makePalindrome(n, k, curNum*10 + i, depth + 1);
if(depth == 0 && i == 0) continue;
for(int i = 0; i <= 9; i++){
}
return;
}
push(curNum);
if((curNum%k) == 0){
}<= 10;
tmp code>
curNum += tmp %10;
curNum *= 10;
while(tmp){
}<= 10;
tmp code>
if((n%2) == 1){
long long tmp = curNum;<2){
if(depth == (n+1)code>
void makePalindrome(int n, int k, long long curNum, int depth){
}
s.insert(str);
}
str += to_string(tmp[i]);
for(int i = 0 ; i < tmp.size(); i++){
string str = "";
sort(tmp.begin(), tmp.end(), [](long long a, long long b) -> long long {return a > b; });
}<= 10;
nn code>
tmp.push_back(nn%10);
while(nn){
long long nn = n;
vector tmp;
void push(long long n){
set s;
public:
class Solution {
Solution Code:
-
-
- The time complexity is O(10^n * n^2 * log(n)) due to the sorting and combination operations.
-
- Then it counts the number of good integers that can be formed by rearranging their digits using the combination formula and a helper function getCnt()
- The solution first generates all possible k-palindromic integers with n digits by recursively generating all possible combinations of digits and then sorting them in descending order
Explanation
-
- O(10^n * n^2 * log(n))
Complexity
-
- The approach used in the solution is to generate all possible k-palindromic integers with n digits, and then count the number of good integers that can be formed by rearranging their digits.
Approach
-
- This problem is about counting the number of good integers that can be rearranged to form a k-palindromic integer.
'알고리즘' 카테고리의 다른 글
Count Symmetric Integers (0) | 2025.04.11 |
---|---|
Count the Number of Powerful Integers (0) | 2025.04.11 |
Minimum Operations to Make Array Values Equal to K (0) | 2025.04.10 |
Minimum Number of Operations to Make Elements in Array Distinct (0) | 2025.04.08 |
Partition Equal Subset Sum (0) | 2025.04.08 |