2018-06-05


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n, k, p, maxFacSum = -1;
vector<int> v, ans, tempAns;
void init() {
    int temp = 0, index = 1;
    while(temp <= n) {
        v.push_back(temp);
        temp = pow(index, p);
        index++;
    }
}
void dfs(int index, int tempSum, int tempK, int facSum) {
    if(tempSum == n && tempK == k) {
        if(facSum > maxFacSum) {
            ans = tempAns;
            maxFacSum = facSum;
        }
        return ;
    }
    if(tempSum > n || tempK > k) return ;
    if(index >= 1) {
        tempAns.push_back(index);
        dfs(index, tempSum + v[index], tempK + 1, facSum + index);
        tempAns.pop_back();
        dfs(index - 1, tempSum, tempK, facSum);
    }
}
int main() {
    scanf("%d%d%d", &n, &k, &p);
    init();
    dfs(v.size() - 1, 0, 0, 0);
    if(maxFacSum == -1) {
        printf("Impossible");
        return 0;
    }
    printf("%d = ", n);
    for(int i = 0; i < ans.size(); i++) {
        if(i != 0) printf(" + ");
        printf("%d^%d", ans[i], p);
    }
    return 0;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 6-4完成:1、周报。——制作过程中遇到问题。上周完成的事忘记。解决方式:每天的复盘中首要写明今天完成的工作内容2...
    片片星阅读 311评论 0 0
  • 烟旧阅读 130评论 0 0
  • 聊起金融,大部分人都会觉得它自带”光环”,会被贴上“多金”的标签。大白话来讲就是——有钱!这是为何呢?因为大部分吃...
    空眸浅笑是你阅读 279评论 1 1
  • 随着五月份鏖战的如期结束,光禾再次以高贵的王者姿态荣耀登顶夺冠,傲视天下群雄。六一篝火晚会上,凯跃人再次沸腾了,只...
    玉雕阅读 129评论 0 0
  • 最近又到了瓶颈期,又不知道该写什么了。好像每过一段时间就会到一次瓶颈期,每次突破又会有新的领悟。到瓶颈期并不可怕,...
    弘丹阅读 2,001评论 25 59