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;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 6-4完成:1、周報(bào)?!谱鬟^(guò)程中遇到問(wèn)題。上周完成的事忘記。解決方式:每天的復(fù)盤(pán)中首要寫(xiě)明今天完成的工作內(nèi)容2...
    片片星閱讀 332評(píng)論 0 0
  • 煙舊閱讀 141評(píng)論 0 0
  • 聊起金融,大部分人都會(huì)覺(jué)得它自帶”光環(huán)”,會(huì)被貼上“多金”的標(biāo)簽。大白話來(lái)講就是——有錢!這是為何呢?因?yàn)榇蟛糠殖?..
    空眸淺笑是你閱讀 293評(píng)論 1 1
  • 隨著五月份鏖戰(zhàn)的如期結(jié)束,光禾再次以高貴的王者姿態(tài)榮耀登頂奪冠,傲視天下群雄。六一篝火晚會(huì)上,凱躍人再次沸騰了,只...
    玉雕閱讀 140評(píng)論 0 0
  • 最近又到了瓶頸期,又不知道該寫(xiě)什么了。好像每過(guò)一段時(shí)間就會(huì)到一次瓶頸期,每次突破又會(huì)有新的領(lǐng)悟。到瓶頸期并不可怕,...
    弘丹閱讀 2,067評(píng)論 25 59

友情鏈接更多精彩內(nèi)容