Ural 1698. Square Country 5 记忆化搜索
来源:互联网 发布:期货数据库 编辑:程序博客网 时间:2024/06/11 17:38
1698. Square Country 5
Time limit: 2.0 second
Memory limit: 64 MB
Memory limit: 64 MB
The first arithmetical operation taught to the children of the Square country is the calculation of squares of positive integers. At the first lesson the children are provided with “easy” numbers, calculating a square of which can be done by writing a few digits in front of them (i.e. 76 is an easy number because 762 = 5776). Of course, the numbers cannot contain leading zeroes. The task shouldn't be too difficult, so the easy numbers shouldn't contain more than n digits. How many different easy numbers can teachers prepare for the first lesson?
Input
The only input line contains an integer n (1 ≤ n ≤ 2000) , the maximal length of the easy number the children can be provided with.
Output
Output the number of different easy numbers consisting of at most n digits.
Sample
1
3
Problem Author: Alex Samsonov
Problem Source: Ural SU Contest. Petrozavodsk Winter Session, February 2009
Problem Source: Ural SU Contest. Petrozavodsk Winter Session, February 2009
方块国的孩子们学到的第一个算术运算是正整数的平方计算.孩子们首先学的是那些"简单"数字的平方计算.所谓简单数字就是那些只需要在原数后加几个数字就可得到原数平方的数字(例如,76是简单数字,因为762=5776).当然,所有`数字都不能包含前导0.平方运算不能太麻烦,所以简单数字都不能超过n位.老师们总共可以准备多少简单数字?
#include <stdio.h>#include <math.h>int n, ans;int a[2005];int b[2005];bool check(int k){ b[k] = 0; for (int i = 0; i <= k; ++i) b[k] += a[i] * a[k - i]; if (k) b[k] += b[k - 1] / 10; return b[k] % 10 == a[k];}void dfs(int k){ if (k >= n) return; for (int i = 9; i >= 0; --i) { a[k] = i; if (check(k)) { if (a[k]) { ans++; } dfs(k + 1); } }}int main(){ scanf("%d", &n); dfs(0); printf("%d\n", ans);}
- Ural 1698. Square Country 5 记忆化搜索
- URAL 1073. Square Country
- ural 1073 Square Country
- ural 1073. Square Country
- ural 1073. Square Country
- Ural 1073. Square Country
- Ural 1073 Square Country
- URAL 1073Square Country
- Ural 1073. Square Country 背包
- Ural 1097. Square Country 2
- URAL 1073 Square Country(DP)
- ural 1148 记忆化搜索
- ural 1009 记忆化搜索
- ural 1073. Square Country 动态规划
- ural 1667 Square Country 3,构造
- URAL 1073. Square Country(完全背包)
- Ural 1073 Square Country (DP)
- ural 1073. Square Country(dp)
- Java语言实现简单FTP软件------>辅助功能模块FTP站点管理的实现(十二)
- [转] 用C语言实现Ping程序功能
- LinuxC之进程
- 龟兔赛跑(hdu2059,dp or贪心)
- 常见相似度量
- Ural 1698. Square Country 5 记忆化搜索
- Hbase安装与简介
- how to analysis the crash dump
- 安装Oracle 11.2.0.2.0 for RedHat5.4_32bit碰到的一些错误--分析并解决
- 了解Google的开源HTML5解析引擎Gumbo
- 两篇很牛的vim使用技巧
- linux内核内存管理学习之一(基本概念,分页及初始化)
- PhysicsEditor的应用
- C++获取系统图标方法