题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k],为了不出现负数 改为:dp[i][j+k] += dp[i-1][j] */ #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <str…
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most i…
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most i…
题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> #include <stdio.h> #include <string.h> using namespace std; ][] ; int main() { int s ; memset(dp,,sizeof(dp)) ; ; i < ; i++) { dp[][i] = ; d…
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ][]; void inti() { memset(dp,,sizeof(dp)); dp[][]=; ; i<=; i++) { ; j<=i*; j++) { ; k<=; k++) {…
题目地址:Ural 1353 定义dp[i][j].表示当前位数为i位时,各位数和为j的个数. 对于第i位数来说.总能够看成在前i-1位后面加上一个0~9.所以状态转移方程就非常easy出来了: dp[i][j]=dp[i][j]+dp[i][j-1]+dp[i][j-2]+.......+dp[i][j-9]: 最后统计就可以. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #inclu…
剑指 Offer 12. 矩阵中的路径 题目链接 题目类似于迷宫的搜索. 需要注意的是,需要首先判断起始搜索的位置,可能有多个起点,都需要一一尝试. 每轮迭代的时候记得将是否遍历标记数组还原为未遍历的状态. package com.walegarrett.offer; /** * @Author WaleGarrett * @Date 2020/12/9 9:09 */ import java.util.Arrays; /** * [["a","b","c…
http://codeforces.com/problemset/problem/837/E   题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)) 输出f(a,b) a=A*gcd(a,b)    b=B*gcd(a,b) 一次递归后,变成了 f(A*gcd(a,b),(B-1)*gcd(a,b)) 若gcd(A,(B-1))=1,那么 这一层递归的gcd(a,b)仍等于上一层递归的gcd(a,b) 也就是说,b-gcd(a,b),有大量的时间…
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b-gcd(a, b)); 求 f(a, b) , a,b <= 1e12 分析: b 每次减 gcd(a, b) 等价于 b/gcd(a,b) 每次减 1 减到什么时候呢,就是 b/gcd(a,b)-k 后 不与 a 互质 可先将 a 质因数分解,b能除就除,不能…
个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当值等于一时就属于A数组,等于0时属于B数组,这样就可以构成递归,即下一个数只有在A数组和不在A数组,发现这个思想真的挺好的. DFS心得:若从第二步开始,动作变得程序化,像地图,只有上下左右,这个是只有为0不为0是就可以用深搜递归思想解决. A university network is compo…
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y).…
Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythago…
//看下这个递归方法,最后输出的值function fn(i){ i++; if(i<10){ fn(i); } else{ return i; } } var result = fn(0); console.log(result); 大部分人都可能一下就会说出结果为10,但是真实的结果是undefined.为什么呢?因为对于每一个函数,没有写return的返回值的时候,其实对于var a = function(); 就是没有给a赋值,那么这个值就是默认的undefined值了,可以typeof…
Discription Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calcul…
题目: http://acm.timus.ru/problem.aspx?space=1&num=1181 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#problem/A 1181. Cutting a Painted Polygon Time limit: 1.0 second Memory limit: 64 MB There is a convex polygon with vertices painted in…
arguments 就像一个数组一样,包含了传递给这个函数的参数 , 以上部分为this的介绍,注意arguments.callee  属性 ,可用于递归调用,其代表的是  : 当前正在运行函数的引用  , 用法 如下 arguments.length 返回的是 传递给这个函数参数的数量…
题目链接 题意 : 中文题 分析 :  价值和重量都太过于大,所以采用折半枚举的方法,详细可以看挑战的超大背包问题 由于 n <= 30 那么可以不必直接记录状态来优化,面对每个用例 直接采用递归回溯的方法来写这个 DP 即可 #include<bits/stdc++.h> #define LL long long #define ULL unsigned long long #define scs(i) scanf("%s", i) #define sci(i) s…
数论题还是好恶心啊. 题目大意:给你两个不超过1e12的数 x,y,定义一个f ( x, y ) 如果y==0 返回 0 否则返回1+ f ( x , y - gcd( x , y ) ); 思路:我们设gcd ( x , y) 为G,那么 设 x  = A*G,y = B*G,我们考虑减去多少个G时x y 的gcd会改变,我们设减去 k个G的时候 x和y 的gcd为改变,即 A*G 和 ( B - k ) * G 的 gcd 改变了,什么情况下会改变呢,就是A 和( B -  k )的gcd…
大意: 给定$a,b$, $1\le a,b\le 1e12$, 定义 $f(a,0)=0$ $f(a,b)=1+f(a,b-gcd(a,b))$ 求$f(a,b)$. 观察可以发现, 每次$b$一定是减去若干个相同的$gcd$, 并且每次减的$gcd$一定是递增的, 并且一定是在$gcd$最接近$b$的时候开始减, 可以预处理出所有这样的位置, 然后模拟. #include <iostream> #include <cstdio> #include <math.h>…
PROBLEM D - Round Subset 题 OvO http://codeforces.com/contest/837/problem/D 837D 解 DP, dp[i][j]代表已经选择了i个元素,当2的个数为j的时候5的个数的最大值 得注意最大值(貌似因为这个喵呜了一大片喵~☆) #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include…
题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a,b),那么b-GCD(a,b) = (B-1)*GCD(a,b),如果此时A和B-1依然互质,那么GCD不变下一次还是要执行b-GCD(a,b).那么GCD什么时候才会变化呢?就是说找到一个最小的S,使得(B-S)%T=0其中T是a的任意一个因子.变形得到:B%T=S于是我们知道S=min(B%T).也…
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/37076755 转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:pid=1579" rel="nofollow">http://acm.hdu.edu.cn/showproblem.php? pid=1579 Problem…
总Time Limit:  10000ms  Memory Limit:  65536kB 有一个奇妙的口袋.总的容积是40,用这个口袋能够变出一些物品,这些物品的整体积必须是40.John如今有n个想要得到的物品,每一个物品的体积各自是a1,a2--an.John能够从这些物品中选择一些,假设选出的物体的整体积是40,那么利用这个奇妙的口袋.John就能够得到这些物品.如今的问题是,John有多少种不同的选择物品的方式. Input 输入的第一行是正整数n (1 <= n <= 20),表示…
剑指 Offer 13. 机器人的运动范围 题目链接 package com.walegarrett.offer; /** * @Author WaleGarrett * @Date 2020/12/9 9:49 */ public class Offer_13 { int m, n; boolean[][] isTraveled; int cnt; int k; int[][] direction = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; public voi…
列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scientific Conference URAL 1353 Milliard Vasya's Function URAL 1260 Nudnik Photographer URAL 1012 K-based Numbers. Version 2 URAL 1073 Square Country URAL 1…
这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define LL long long LL dp[][]; int main() { int i,n; scanf("%d",&n); dp[][] = ;d…
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 从Sizzle1.8开始,这是Sizzle的分界线了,引入了编译函数机制 网上基本没有资料细说这个东东的,sizzle引入这个实现主要的作用是分词的筛选,提高逐个匹配的效率 我们不直接看代码的实现,通过简单的实现描述下原理: 以下是个人的理解,如果有错误欢迎指出! Javascript有预编译与我们说的编译函数是不同的概念 什么是JavaScript的“预编译”? function Aaron() { alert("he…
背包型动态规划 1.Wikioi 1047 邮票面值设计 题目描写叙述 Description 给定一个信封,最多仅仅同意粘贴N张邮票,计算在给定K(N+K≤40)种邮票的情况下(假定全部的邮票数量都足够),怎样设计邮票的面值.能得到最大值MAX.使在1-MAX之间的每个邮资值都能得到. 比如.N=3,K=2,假设面值分别为1分.4分.则在1分-6分之间的每个邮资值都能得到(当然还有8分.9分和12分):假设面值分别为1分.3分,则在1分-7分之间的每个邮资值都能得到.能够验证当N=3.K=2时…
[代码为王] http://www.cnblogs.com/codeisking [洛谷] http://www.luogu.org/ NOIP2015 金币 扫雷游戏 求和 推销员 枚举 数学 优先队列 NOIP2014 珠心算测验 比例简化 螺旋矩阵 子矩阵 数学 数学.递归 深搜.DP NOIP2013 计数问题 表达式求值 小朋友的数字 车站分级 NOIP2012 质因数分解 寻宝 摆花 文化之旅 NOIP2011 数字反转 统计单词数 瑞士轮 表达式的值 NOIP2010 数字统计 接…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a non-negative value ai is assigned.An ordered pair of nodes (u,v) is said to be weak if  (1) u…