1103 Integer Factorization(30 分)

#include
using namespace std;
vectortemp,path;
int n,k,p,maxsum;
void DFS(int v,int nowk,int nowsum)
{
    if(v<=0||nowk>k||nowsum>n)return;
    if(nowk==k&&nowsum==n)
    {
        int sum=0;
        for(int i=0;imaxsum)path=temp,maxsum=sum;
        return;
    }
    temp.push_back(v);
    DFS(v,nowk+1,nowsum+pow(v,p));
    temp.pop_back();
    DFS(v-1,nowk,nowsum);
}
int main()
{
    scanf("%d%d%d",&n,&k,&p);
    int v=sqrt(n);
    DFS(v,0,0);
    if(path.size())
    {
        printf("%d =",n);
        for(int i=0;i

你可能感兴趣的:(1103 Integer Factorization(30 分))