UVa 1645 Count (递推,数论)
题意:给定一棵 n 个结点的有根树,使得每个深度中所有结点的子结点数相同。求多棵这样的树。
析:首先这棵树是有根的,那么肯定有一个根结点,然后剩下的再看能不能再分成深度相同的子树,也就是说是不是它的约数。那么答案就有了,
我们只要去计算n-1的约数有多少棵不同的树,然后就有递推式了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL dp[maxn]; void init(){
dp[1] = 1; dp[2] = 1;
for(int i = 2; i < 1000; ++i){
for(int j = 1; j <= i; ++j)
if(i % j == 0) dp[i+1] = (dp[i+1] + dp[j]) % mod;
}
} int main(){
init();
int kase = 0;
while(scanf("%d", &n) == 1){
printf("Case %d: %lld\n", ++kase, dp[n]);
}
return 0;
}
UVa 1645 Count (递推,数论)的更多相关文章
- 紫书 习题 10-10 UVa 1645(递推)
除了根节点以外,有n-1个节点,然后就看n-1的因数有那些,所有因数加起来(递推)就好了. #include<cstdio> #define REP(i, a, b) for(int i ...
- UVa 10520【递推 搜索】
UVa 10520 哇!简直恶心的递推,生推了半天..感觉题不难,但是恶心,不推出来又难受..一不小心还A了[]~( ̄▽ ̄)~*,AC的猝不及防... 先递推求出f[i][1](1<=i< ...
- Uva 10446【递推,dp】
UVa 10446 求(n,bcak)递归次数.自己推出来了一个式子: 其实就是这个式子,但是不知道该怎么写,怕递归写法超时.其实直接递推就好,边界条件易得C(0,back)=1.C(1,back)= ...
- UVa 10943 (数学 递推) How do you add?
将K个不超过N的非负整数加起来,使它们的和为N,一共有多少种方法. 设d(i, j)表示j个不超过i的非负整数之和为i的方法数. d(i, j) = sum{ d(k, j-1) | 0 ≤ k ≤ ...
- UVa 557 (概率 递推) Burger
题意: 有两种汉堡给2n个孩子吃,每个孩子在吃之前要抛硬币决定吃哪一种汉堡.如果只剩一种汉堡,就不用抛硬币了. 求最后两个孩子吃到同一种汉堡的概率. 分析: 可以从反面思考,求最后两个孩子吃到不同汉堡 ...
- UVA 1645 Count
https://vjudge.net/problem/UVA-1645 题意:有多少个n个节点的有根树,每个深度中所有节点的子节点数相同 dp[i] 节点数为i时的答案 除去根节点还有i-1个点,如果 ...
- Coin Toss(uva 10328,动态规划递推,限制条件,至少转至多,高精度)
有n张牌,求出至少有k张牌连续是正面的排列的种数.(1=<k<=n<=100) Toss is an important part of any event. When everyt ...
- UVA - 11021 - Tribles 递推概率
GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the ...
- 紫书 例题 9-4 UVa 116 ( 字典序递推顺序)
这道题在递推方式和那个数字三角形有一点相像,很容易推出来 但是这道题要求的是字典序,这里就有一个递推顺序的问题 这里用逆推,顺推会很麻烦,为什么呢? 如果顺推的话,最后一行假设有种情况是最小值,那么你 ...
随机推荐
- Android 设计模式之单例模式
设计模式是前人在开发过程中总结的一些经验,我们在开发过程中依据实际的情况,套用合适的设计模式,能够使程序结构更加简单.利于程序的扩展和维护.但也不是没有使用设计模式的程序就不好.如简单的程序就不用了, ...
- Android开源git40个App源代码
(JamsMusicPlayer)非常棒的音乐播放器(new) (F8)日程安排的软件 (Conversations)基于XMPP的应用 (Bitocle)能够在手机上查看自己github ...
- ActionChains报错问题总结
在使用Python2.7+Selenium3.0.2+Firefox50.1时,鼠标事件ActionChains运行总是报错,报错信息如下: C:\Python36\python3.exe C:/Us ...
- IP和归属地
ip: http://www.ip.cn/index.php?ip=10.132.98.143 归属地: http://www.ip138.com:8080/search.asp?action=mob ...
- “ 不确定 "限制值的使用
前言 前篇文章解释了限制值的五种类型以及获取它们的方法.但是对于其中可能不确定的类型( 45类型 ),当限制值获取函数返回-1的时候,我们无法仅通过这个函数返回值-1来判断是限制值获取失败还是限制值是 ...
- 多媒体开发之---h.264 SPS PPS解析源代码,C实现一以及nal分析器
http://blog.csdn.net/mantis_1984/article/details/9465909 http://blog.csdn.net/arau_sh/article/detail ...
- 模式识别之分类器knn---c语言实现带训练数据---反余弦匹配
邻近算法 KNN算法的决策过程 k-Nearest Neighbor algorithm是K最邻近结点算法(k-Nearest Neighbor algorithm)的缩写形式,是电子信息分类器算 ...
- secureCRT与vim配置
折腾了一天,给服务器新装了centos系统,用crt连接,vim用着很不习惯. 修改配色,快捷键啥的都不怎么起效. 后来发现.crt里的会话选项-终端-仿真 里配成xtream,使用颜色方案就可以了.
- IOS 单元测试
本文转载至 http://blog.csdn.net/fengsh998/article/details/8109293 IOS 自带单元测试. 1.在创建时,将include Unit Tests钩 ...
- 2016/07/07 wamp中apache2.4.9允许外部访问的配置 重点是版本 版本不同配置效果不同
wamp安装包中安装好服务器之后只能使用127.0.0.1来访问了,如果我们要设置多个站点或其它像192.168.1.1这种就需要进行一下修改,具体步骤如下. wamp-apache2.4.9允许 ...