URAL 1014 Product of Digits
2013-11-22 13:02
363 查看
给定一个整数N,找出最小的正整数Q,使得Q的各位数的积等于N。
直接深搜
直接深搜
#include <iostream> using namespace std; #include <vector> #include <algorithm> int flag; vector<int> result; void dfs(int num) { if (flag==1) return; if (num < 10) { result.push_back(num); flag=1; return; } int i; for (i=9;i>=2;i--) { if (num % i==0) { result.push_back(i); dfs(num/i); if (flag==1) return; result.pop_back(); } } } int main() { int n; while (cin >> n) { if (n==0) cout << "10" << endl; else { flag = 0; result.clear(); dfs(n); sort(result.begin(), result.end()); if (flag==1) { for (int i = 0; i < result.size(); i++) cout << result[i]; } else cout << "-1"; cout << endl; } } return 0; }
相关文章推荐
- ural 1014 Product of Digits
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- ural 1014 the product of digits
- Ural 1014-The Product of Digits
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- URAL 1014 Product of Digits
- Timus 1014. The Product of Digits
- UVa 993 - Product of digits
- UVa 993 - Product of digits
- UVA 993 Product of digits
- uva 993 Product of digits
- UVa:993 Product of digits
- uva993 Product of digits
- uva 993 - Product of digits
- uva 993 Product of digits(分解因子)
- UVa 993 - Product of digits
- uva 993 - Product of digits
- uva 993 Product of digits (贪心 + 分解因子)
- How to arrange 10 digits so that the product of the some of them is equal to a number represented by the remaining digits
- UVa 993 - Product of digits