POJ 3421 X-factor Chains (约数枚举)
来源:互联网 发布:淘宝的慈恩数码怎么样 编辑:程序博客网 时间:2024/06/05 04:28
X-factor Chains
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5605 Accepted: 1770
Description
Given a positive integer X, an X-factor chain of length m is a sequence of integers,
1 = X0, X1, X2, …, Xm = X
satisfying
Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.
Now we are interested in the maximum length of X-factor chains and the number of chains of such length.
Input
The input consists of several test cases. Each contains a positive integer X (X ≤ 220).
Output
For each test case, output the maximum length and the number of such X-factors chains.
Sample Input
23410100
Sample Output
1 11 12 12 24 6
枚举约数 然后dp即可
AC代码如下:
////POJ 3421 X-factor Chains//// Created by TaoSama on 2015-03-31// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;int n, len[1500], dp[1500];int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);//freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(cin >> n) { vector<int> factor; for(int i = 1; i * i <= n; ++i) { if(n % i == 0) { factor.push_back(i); if(i != n / i) factor.push_back(n / i); } } sort(factor.begin(), factor.end()); int sz = factor.size(); for(int i = 0; i < sz; ++i) { len[i] = dp[i] = 1; for(int j = 0; j < i; ++j) { if(factor[i] % factor[j] == 0) { if(len[i] < len[j] + 1) { len[i] = len[j] + 1; dp[i] = dp[j]; } else if(len[i] == len[j] + 1) dp[i] += dp[j]; } } } cout << len[sz - 1] - 1 << ' ' << dp[sz - 1] << endl; } return 0;}
0 0
- POJ 3421 X-factor Chains (约数枚举)
- POJ 3421 - X-factor Chains(数学)
- POJ-3421-X-factor Chains
- poj 3421 X-factor Chains
- Poj 3421-X-factor Chains
- POJ 3421 X-factor-Chains
- poj 3421 X-factor Chains
- POJ 3421 X-factor Chains(数论)(筛法)()
- poj 3421 --X-factor Chains(数学、组合)
- POJ 3421 X-factor Chains 排列组合
- X-factor Chains (poj 3421 数学排列组合)
- poj 3421 X-factor Chains(分解质因数+组合数学)
- POJ 3421X-factor Chains【分解质因子+组合数学】
- POJ 3421 X-factor Chains 已被翻译
- poj 3421 X-factor Chains(数因子分解)
- poj 3421 X-factor Chains 素数筛选 因子分解
- POJ 3421 X-factor Chains 分解质因数 排列组合
- X-factor Chains(素数)
- newInstance()和new()
- java内部类
- codeforces 4D Mysterious Present
- 随想录(关于ucore)
- snmp渗透辅助脚本两则
- POJ 3421 X-factor Chains (约数枚举)
- ssh2与基于jquery的ajax配合方法
- 32位代码段和16位代码段切换的实例
- HDU 5195 DZY Loves Topological Sorting(线段树单点更新)
- 同时运行两个函数
- nyoj23取石子(一)
- B\S备忘录10——普通的反射返回普通的一天
- 如何把txt文档导入到plist文件中
- 我的第一次