不是VIP会员,不能显示答案

题目解答

题目:
(水仙花数问题)给定一个n <= 15,令所有十进制下长度为n的数,其各数位的n次方之和等于这个数本身,我们称这个数为水仙花数,例如当n = 3, 153 = 1^3 + 5^3 + 3^3。当n = 4, 1634 = 1^4 + 6^4 + 3^4 + 4^4。

你需要求出所有n位的水仙花数的和。



#include <cstdio>

using namespace std;



long long cost[10], ans;



int cnt[10], t[10], n;



void dfs(int rest, int now, long long current) {

if (rest == 0) {

long long temp = current;

for (int i = 0; i < 10; i++)

t[i] = 0;

while (temp > 0) {

++t[temp % 10];

temp /= 10;

}

bool flag = 1;

for (int i = 0; i < 10; i++)

if (cnt[i] != t[i]) {

flag = 0;

break;

}

if (flag) {

__(1)__;

}

return;

}

if ( __(2)__ ) {

return;

}

for (cnt[now] = 0; cnt[now] <= rest; cnt[now]++)

dfs(rest - cnt[now], now + 1, __(3)__ );

cnt[now] = 0;

}

int main()

{

scanf("%d", &n);

for (int i = 0; i < 10; i++) {

cost[i] = 1;

for (int j = 0; j < n; j++)

__(4)__ ;

}

dfs( __(5)__ );

printf("%lld\n",ans);

return 0;

}


选择题

1) ⑴处应填( )。

2) ⑵处应填( )。

3) ⑶处应填( )。

4) ⑷处应填( )。

5) ⑸处应填( )。
考点:
分析:
解答:
评论:
老师: