PAT1103——Integer Factorization
来源:互联网 发布:400块一家收淘宝店铺 编辑:程序博客网 时间:2024/06/09 16:11
DFS很简单的,lz只是想抒发感慨所以才po代码
int num, k, p;int factor[400];vector<int> ans, ans_temp;int Max = 0;void dfs(int tot, int sum, int index, int level){ if(level > k) return; if(level == k){ if(tot == num){ if(sum > Max){ ans = ans_temp; Max = sum; } } } else{ if(tot >= num) return; for(int i = index; i>= 1; i--){ ans_temp.push_back(i); dfs(tot + factor[i], sum + i, i, level+1); ans_temp.pop_back(); } }}int main(){ cin>>num>>k>>p; int n = 1; while(pow(n, p) <= num) {factor[n] = (int)pow(n, p); n++;} for(int i = n-1; i>=1; i--){ ans_temp.push_back(i); dfs(factor[i], i, i, 1); ans_temp.pop_back(); } if(ans.empty()) cout<<"Impossible\n"; else{ auto it = ans.begin(); printf("%d = %d^%d", num, *it, p); it++; while(it != ans.end()){ printf(" + %d^%d", *it, p); it++; } } return 0;}
tb逛了逛泳衣,放下了晚饭的念头,按照现在的婚配观,lz是要绝后啊不行要夹缝中求生存穿上运动裤去跑步了。��
阅读全文
0 0
- PAT1103——Integer Factorization
- Integer Factorization
- PAT1103
- pat1103
- 1103. Integer Factorization (30)【搜索+剪枝】——PAT (Advanced Level) Practise
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- pat 1103 Integer Factorization
- 1103. Integer Factorization
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization
- Myeclipse10 创建Maven项目有如下几种!
- 测试看看
- Unity3D_组合体和预制件
- 购物车买卖伤害2.0 (结版)
- Mac OS下Android Studio的升级问题
- PAT1103——Integer Factorization
- Signal ()函数详细介绍 Linux函数
- forward 和redirect 的区别
- 斐波那契数列实用解法
- Android---创建定时任务
- 自然语言处理学习(二):概率化的上下文无关文法
- mybatis异常:Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}
- 20170911_const在类中的应用
- prototype的入门基础