数的计数(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 ...
随机推荐
- Android闪光灯操作
flashMode=Camera.Parameters.FLASH_MODE_TORCH;----常亮效果 Camera.Parameters.FLASH_MODE_ON----一闪一闪的效果
- VBS调用windows api函数(postmessage)实现后台发送按键脚本
'=========================================================================='' VBScript Source File - ...
- Unity3d之将terrain转化成mesh
Unity3d中,terrain还是比较耗的,DrawCall数也比较多,为了优化性能,可能需要将terrain转化成mesh. 现提供一工具,思路是根据terrain高度图生成mesh等,可参考: ...
- Spring Bean 生命周期
转自:也谈Spring Bean的生命周期 开篇先用一张老图描述下Spring中Bean容器的生命周期. 插叙一下,记得某个博文中提到:“Spring的Bean容器只管理非单例Bean的生命周期,单例 ...
- hdu_5748_Bellovin(LIS)
题目链接:hdu_5748_Bellovin 题意: 给你一个数列ai,设f(a1,a2,a3,..an)=(f1,f2,f3,...,fn),其中fi表示以ai结尾的最长递增子序列长度,注意:必须要 ...
- C++之文件输入输出
在这里遇见不少的问题,其中的路径问题就是在windows中,\\转义字符才能准确的表示路径 #include <iostream> #include <fstream> #in ...
- LeetCode OJ 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- MySQL 的实时性能监控利器【转】
操作系统及MySQL数据库的实时性能状态数据尤为重要,特别是在有性能抖动的时候,这些实时的性能数据可以快速帮助你定位系统或MySQL数据库的性能瓶颈,就像你在Linux系统上使用「top,sar,io ...
- Nginx运行Laravel的配置
修改nginx.conf.修改前记得备份一下,万一改错了还能还原回去. server { listen 80; server_name localhost; set $root_path '/usr/ ...
- C: Run a System Command and Get Output? 在C程序中调用工具,并且得到结果。
现在在做一个WIFI API相关的库,这样就可以让其他的人管理WIFI. 在调用API的时候要回复SHELL打印的信息,比如说搜索热点,而且不在SHELL中打印出来.然后把信息返回给调用API的程序. ...