zoukankan      html  css  js  c++  java
  • 【9408】数的计数

    Time Limit: 3 second
    Memory Limit: 2 MB

    问题描述:
    我们要求找出具有下列性质的数的个数(包含输入的自然数n)
    先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理 :
    1.不作任何处理:
    2.在它的左边加上一个自然数,但该自然数不能超过原数的一半;
    3.加上数后,继续按此规则进行处理,直到不能再而 自然数为止。
    Input

    输入文件仅一行,输入n(n≤1000)。

    Output

    输出符合条件的数目

    Sample Input

    6

    Sample Output

    6 满足条件的数为6,16,26,126,36,136

    【题目链接】:http://noi.qz5z.com/viewtask.asp?id=9408

    【题解】

    设f[i]为以i这个数字结尾的数字(符合要求)的个数;
    f[i]+=f[j](j∈1..(i/2)
    f[0] = f[1] = 1;f[2] = 2;f[3] = 2;f[4] = 4….

    【完整代码】

    //#include <bits/stdc++.h>
    #include <cstdio>
    #include <string>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    const int MAXN = 1200;
    
    int n,f[MAXN] = {0};
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        f[0] = 1;f[1] = 1;f[2] = 2;f[3] = 2;f[4] = 4;
        for (int i = 5;i <= 1000;i++)
        {
            f[i] = 1;
            for (int j = 1;j <= (i/2);j++)
                f[i]+=f[j];
        }
        cin >> n;
        cout << f[n]<<endl;
        return 0;
    }
  • 相关阅读:
    JavaScrip(二)JavaScrip语法基础
    JavaScrip(一)JavaScrip的写法
    MySQL远程登陆
    JavaScript简介
    Fedora防火墙配置
    sqlalchem表关联(一对多,一对一,多对多)
    常见的SQLALCHEMY列类型
    flask使用配置文件
    算法(一)概述
    pom
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626955.html
Copyright © 2011-2022 走看看