数的计数(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)的更多相关文章

  1. ACM——数的计数

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1050 数的计数 时间限制(普通/Jav ...

  2. LFYZ-OJ ID: 1026 数的计数(数的计算)NOIP2001

    数的计算(数的计数) 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数n).先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理: 不作任何处理; 在它的左边加上 ...

  3. hdu---(1280)前m大的数(计数排序)

    前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  4. 有趣的数-回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  5. [Swift]LeetCode248.对称数 III $ Strobogrammatic Number III

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  6. [Swift]LeetCode264.丑数 II | Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  7. [Swift]LeetCode313. 超级丑数 | Super Ugly Number

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  8. [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 ...

  9. 有趣的回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

随机推荐

  1. C相关的图书(链接不可用)

    Visual C++视频技术方案宝典.pdf: http://www.t00y.com/file/17628500 Windows 图形编程.pdf: http://www.t00y.com/file ...

  2. OpenCV成长之路:直线、轮廓的提取与描述

    http://ronny.blog.51cto.com/8801997/1394139 OpenCV成长之路:直线.轮廓的提取与描述 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 . ...

  3. hdu_3067_小t的游戏(脑洞)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3067 题意:中文,不解释 题解:一看就知道是要找规律的题,都是有循环节的,看代码. #include ...

  4. POJ2524:Ubiquitous Religions (并查集模板)

    Description There are so many different religions in the world today that it is difficult to keep tr ...

  5. subversion SVN global ignore pattern

    *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store */bin */ ...

  6. docker log 文件 清理

    1 查看docker log 文件位置  docker inspect *** 2 定时清理 runcate -s 0 /var/lib/docker/containers/*/*-json.log

  7. linux CTRL+Z

    关于 linux 系统中使用ctrl+Z 的使用 (1) CTRL+Z停止进程并放入后台 (2) jobs 显示当前暂停的进程 (3) bg %N 使第N个任务在后台运行(%前有空格) ,N 为任务号 ...

  8. hr定位

    css里写 <style> hr{ position:relative; top: 500px; } </style> 重要!!! hr不能绝对定位, 只能相对定位,所以 hr ...

  9. PatrolRobot(UVa1600)BFS

    PatrolRobot(UVa1600)BFS 珉黻郐距 河吏蝉醉 闵棵黏言 芤她之瞌 褰上稽莨 錾傻奉 郦玫睃芩 摇摇头还没回答魏海洪就抢先回答道:呵呵你们几个别试 蚰镉氡 钬 绦可 ...

  10. 解决不能打开wifi问题

    使用 命令svc wifi来调试,避免使用GUI 相关资料  https://community.freescale.com/thread/319407 D/WifiService( 313): se ...