1103.Integer Factorization (30)...to be continued...
来源:互联网 发布:网络控制系统的应用 编辑:程序博客网 时间:2024/06/06 01:14
1103.Integer Factorization (30)…to be continued…
pat-al-1103
2017-03-02
- dfs
- 要记录的数据有点多,要细心
/** * pat-al-1103 * 2017-03-02 * Cpp version * Author: fengLian_s */#include<stdio.h>#include<vector>using namespace std;int n, k, p, maxFacSum = -1;vector<int> fac, ans, tmp;int power(int x){ int ans = 1; for(int i = 0;i < p;i++) { ans *= x; } return ans;}void init(){ int i = 0, tmp = 0; while(tmp <= n) { fac.push_back(tmp); tmp = power(++i); }}void dfs(int index, int nowK, int sum, int facSum){ if(nowK == k && sum == n) { if(facSum > maxFacSum) { ans = tmp; maxFacSum = facSum; } return; } if(nowK > k || sum > n) return; if(index > 0) { tmp.push_back(index); dfs(index, nowK+1, sum+fac[index], facSum+index); tmp.pop_back(); dfs(index-1, nowK, sum, facSum); }}int main(){ freopen("in.txt", "r", stdin); scanf("%d%d%d", &n, &k, &p); init(); dfs(fac.size()-1, 0, 0, 0); if(maxFacSum == -1) printf("Impossible"); else { printf("%d = %d^%d", n, ans[0], p); for(int i = 1;i < ans.size();i++) printf(" + %d^%d", ans[i], p); } putchar('\n'); return 0;}
-TBC-
0 0
- 1103.Integer Factorization (30)...to be continued...
- 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 (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 (30)
- 1103. Integer Factorization (30)
- 1103. Integer Factorization (30)
- BZOJ 1500 splay终结版...
- mvn 创建项目架构
- demo
- Volley框架(三):使用Volley提交表单数据
- PYTHON
- 1103.Integer Factorization (30)...to be continued...
- 数据库mysql总结(一)
- 结合Struts+Spring+jdbc做的一个小项目
- Linux.分区、格式化、挂载
- Android应用坐标系统全面详解
- HTTP1.0/1.1区别
- 【黑色飞鱼教程】今天来讲讲115怎么玩得转~
- 喵哈哈村的魔法考试 Round #2 (Div.2) B.喵哈哈村的种花魔法 线段树 区间更新 单点查询
- android 拍照及录短视频---练习