数的计数(number)
数的计数(number)
题目描述
我们要求找出具有下列性质数的个数(包含输入的自然数n),先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理:
(1)不作任何处理;
(2)在它的左边加上一个自然数,但该自然数不能超过原数的一半;
(3)加上数后,继续按此规则进行处理,直到不能再加自然数为止。
输入
一个正整数n。
输出
符合以上性质的数的个数。
样例输入
6
样例输出
6
提示
样例说明:满足条件的数为6,16,26,36,126,136。
分析:暴搜会超时,所以考虑dp,dp[i]=sum[i/2]+1,sum[i]=sum[i-1]+dp[i],维护一个前缀和数组就好了
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,dp[maxn],a[maxn];
void init()
{
for(int i=;i<=;i++)
{
dp[i]=a[i/]+;
a[i]=a[i-]+dp[i];
}
}
int main()
{
int i,j,k,t;
init();
scanf("%d",&n);
printf("%d\n",dp[n]);
//system ("pause");
return ;
}
数的计数(number)的更多相关文章
- ACM——数的计数
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1050 数的计数 时间限制(普通/Jav ...
- LFYZ-OJ ID: 1026 数的计数(数的计算)NOIP2001
数的计算(数的计数) 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数n).先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理: 不作任何处理; 在它的左边加上 ...
- hdu---(1280)前m大的数(计数排序)
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 有趣的数-回文数(Palindrome number)
文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...
- [Swift]LeetCode248.对称数 III $ Strobogrammatic Number III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [Swift]LeetCode264.丑数 II | Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [Swift]LeetCode313. 超级丑数 | Super Ugly Number
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...
- [Swift]LeetCode414. 第三大的数 | Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- 有趣的回文数(Palindrome number)
文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...
随机推荐
- wmts调用路径手工合成
wmts调用路径手工合成 一般OGC WMTS地图只提供了xml描述,地图应用常常要合成WMTS完整的调用URL.我们需要获知以下参数: BaseURL:例如 "http://10.36.5 ...
- html 框架属性
<html> <head> <title></title> </head> <frameset col ...
- ArrayList implementation
check here. tip: 当使用remove方法时,index后边的元素要自动前移.Nothing special.
- 配置php时。提示的错误session_start(): Failed to initialize storage module解决办法
当浏览器输入访问地址后 报这样的错时----session_start(): Failed to initialize storage module 进入到此目录vi /usr/local/php/e ...
- LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义
先简单的介绍下关于LVS负载均衡 LVS(Linux Virtual Server)Linux服务器集群系统 针对高可伸缩,高可用服务的需求,给予IP层和内容请求分发的负载均衡调度解决方法,并在Li ...
- sqlserver 批量修改表前缀
先把第一句话放到sqlserver查询器中执行一下.然后把查询结果复制出来,进行编辑...一看你就懂了..简单的sql语句拼装 select ' exec sp_rename "' + na ...
- weblogic11g 配置数据源
配置连接数据源步骤详解: 服务器:Weblogic11g,使用JNDI配置 步骤一: 输入http://localhost:7001/console/,登录控制台: 步骤二:按下图要求配置后,进入“下 ...
- wl18xx wifi编译出现没有编译wlcore_sdio的情况
打开config.mk ........................................................................................ ...
- drupal错误: Maximum execution time of 240 seconds exceeded
drupal7.5安装完成,导入汉化包时,出现错误: Fatal error: Maximum execution time of 240 seconds exceeded in D:\phpweb\ ...
- make 命令执行时,报错“missing separator stop”
在Makefile文件中,命令必须以[tab]键开始.