题解

237 条题解

  • 0
    @ 2020-08-07 15:24:11

    递归思路

    #include<iostream>
    using namespace std;
    
    int ans=1,n;
    void solve(int m){
        if(m==1){
            //ans++;如果在这里记录答案,只是结果中包含1的答案,不完整
            return ;
        }
        int x=m/2;
        for(int i=x; i>=1; i--)//对应题目加上不超过原数一半的全部自然数
        {
                ans++;
              solve(i); 
        }
    }
    int main(){
        cin>>n;
        solve(n);
        cout<<ans;
        return 0;
    } 
    
  • 0
    @ 2019-01-15 21:24:43

    #include<iostream>
    using namespace std;
    int r=0;//定义一个全局变量record的缩写,记录个数
    inline void digui(int n)//这个地方inline应该不起作用。感觉有 就加了
    {
    if(n/2==0)//判断是不是一半
    {
    return;
    }
    for(int i=1;i<=n/2;i++)//枚举每一种
    {//用树的图样子更好理解.
    r++;
    digui(i);
    }
    return ;
    }
    int main(){
    int n;
    cin>>n;
    r++;
    digui(n);
    cout<<r<<endl;
    return 0;
    }//对于这个题,本人希望你能够用笔写一下 就能找出关系虽然我手机上过不了,但你网上就能。

  • 0
    @ 2018-08-16 16:12:47

    #include<bits/stdc++.h>
    using namespace std;
    int h[1001];
    int fun(int n) {
    int i;
    h[1]=1;
    for(i=2; i<=n; i++) {
    if(i%2==1)h[i]=h[i-1];
    else h[i]=h[i-1]+h[i/2];
    }
    return h[n];
    }
    int main() {
    int n;
    while(scanf("%d",&n)!=EOF) {
    printf("%d\n",fun(n));
    }
    return 0;
    }
    已经AC

  • 0
    @ 2018-08-14 22:24:39

    #include<bits/stdc++.h>
    using namespace std;
    int n;
    int f[1001];//存每一位数的种类
    int main(){
    cin>>n;
    for(int i=1;i<=n;i++){ //1-n的递推
    for(int j=1;j<=i/2;j++){
    f[i]+=f[j]; //每一位叠加
    }
    f[i]++; //加上本身
    }
    cout<<f[n];//输出n的种类
    return 0;
    }

  • 0
    @ 2018-01-31 19:06:32
    #include<bits/stdc++.h>
    int num=0;
    int find(int n){
        ++num;
        for(int i=n/2;i>=1;--i) find(i);
    }
    int main(){
        int n;
        scanf("%d",&n);
        find(n);
        printf("%d",num);
    }
    
  • 0
    @ 2017-07-23 09:51:06

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    #include <cctype>
    #include <vector>
    #include <queue>
    #include <set>
    #include <bitset>
    #include <cassert>
    #include <map>
    #include <string>
    #include <sstream>
    #include <ctime>
    using namespace std;
    int x;
    int dfs(int n)
    {
    int i,a=0;
    if(n==1)
    {
    return 0;
    }
    else
    {
    a+=n/2;
    for(i=1;i<=n/2;i++)
    {
    a+=dfs(i);
    }

    }
    return a;
    }
    int main()
    {
    scanf("%d",&x);
    printf("%d",dfs(x)+1);
    return 0;
    }

  • 0
    @ 2017-05-08 09:03:26

    递推即可

    #include<iostream>  
    using namespace std;  
    int main()  
    {  
        int a[1001],n;  
        cin>>n;  
        a[1]=1;  
        for(int s=2;s<=n;s++)  
        {  
            a[s]=0;  
            for(int i=1;i<=s/2;i++)  
            {  
                a[s]+=a[i];  
            }  
            a[s]++;  
        }  
        cout<<a[n];  
        return 0;  
    }  
    
  • 0
    @ 2016-10-30 21:08:02

    其实题意不太清,简述:将n作出操作后会形成新的数列,实际上数的是能构成多少合法数列,且过程中可任意停止操作,即任意不同的前缀数列都可称为新数列。则用dp来做,f[i]表示以 i 这个数字为开头可生成的所有新数列.
    则可递推f[i]=f[1]+f[2]+...+f[i/2];有兴趣的同学可以用前缀和优化一小下下。。
    下面是0msAC代码:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int f[1005],n;
    int main()
    {
    scanf("%d",&n);
    f[1]=1;
    for(int i=2;i<=n;i++){
    f[i]=1;
    for(int j=1;j<=(i/2);j++){
    f[i]+=f[j];
    }
    }
    cout<<f[n];
    }

  • 0
    @ 2016-07-22 16:04:39
    #include<iostream>
    using namespace std;
    const int maxn = 1000 + 5;
    int n, a[maxn]={0};
    int dfs(int t){
        int h= t / 2;
        if(a[h]) return a[h];
        a[h] = 1;
        for(int i = 1; i <= h; i++) a[h] += dfs(i);
        return a[h];
    }
    int main(){
        cin >> n;
        cout << dfs(n);
        return 0;
    
    }
    
  • 0
    @ 2016-07-14 16:51:42

    #include <cstdio>

    int dfs(int x){
    int half,sum=1;
    if(x%2==0)
    half=x/2;
    else
    half=(x-1)/2;
    for(int i=1;i<=half;i++)
    sum+=dfs(i);
    return sum;
    }

    int main(){
    int n;
    scanf("%d",&n);
    int total=dfs(n);
    printf("%d",total);
    return 0;
    }

  • 0
    @ 2016-07-12 09:14:05

    var n,i:integer;
    f:array[0..1001] of longint;
    begin
    readln(n);
    f[0]:=1;
    for i:=1 to n do
    if i mod 2=1 then f[i]:=f[i-1]
    else
    f[i]:=f[i-1]+f[i div 2];
    writeln(f[n]);
    end.
    So easy!

  • 0
    @ 2016-07-09 08:22:04

    此题太水,随便就过了
    var
    s,n:longint;
    procedure dt(m:longint);
    begin
    if m>0 then while m>0 do
    begin
    inc(s);
    dt(m div 2);
    dec(m);
    end;
    end;
    begin
    readln(n);
    s:=1;
    dt(n div 2);
    write(s);
    end.

  • 0
    @ 2016-07-03 18:04:39

    C:
    #include <stdio.h>
    int main() {
    long long A[1001];
    int n;
    int i;
    A[1] = 1;
    scanf("%d", &n);
    for(i=2; i<=n; i++) {
    if(i%2 == 0) A[i] = A[i/2] + A[i-1];
    else A[i] = A[i-1];
    }
    printf("%I64d", A[n]);
    return 0;
    }

  • 0
    @ 2016-04-20 19:31:19

    var
    a:array[1..1000]of longint;
    i,n:longint;
    begin
    a[1]:=1;
    readln(n);
    for i:=2 to n do
    if odd(i) then a[i]:=a[i-1]
    else a[i]:=a[i-1]+a[i div 2];
    writeln(a[n]);
    end.

  • 0
    @ 2016-03-23 21:47:28

    晕_(:з」∠)_这都能A
    ```java
    import java.util.*;
    import java.math.*;

    public class Main {
    static BigInteger count = BigInteger.ZERO;

    static void checkAndRun(int x) {
    if (x == 0) {
    count = BigInteger.ONE;
    } else {
    loop(x);
    }
    }

    static void loop(int x) {
    if (x > 0) {
    count = count.add(BigInteger.ONE);
    } else {
    return;
    }
    for (int i = x / 2; i >= 0; i--) {
    loop(i);
    }
    }

    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    checkAndRun(scanner.nextInt());
    System.out.println(count.toString());
    scanner.close();
    }
    }
    ```

  • 0
    @ 2016-03-18 22:56:28

    记忆化搜索
    ```pascal
    var n,i:longint;
    a:array[0..1001] of longint;
    function cal(k:longint):longint;
    var i,ans:longint;
    begin
    if k=0 then exit;
    if a[k]<>-1 then exit(a[k]);
    ans:=k div 2;
    for i:=1 to k div 2 do begin
    inc(ans,cal(i));
    end;
    a[k]:=ans;
    cal:=ans;
    end;

    begin
    fillchar(a,sizeof(a),-1);
    read(n);
    write(cal(n)+1);
    end.
    ```

  • 0
    @ 2016-03-09 13:09:03

    暴力出奇迹

  • 0
    @ 2016-02-19 14:35:43

    递推。规律。
    ```
    /* ***********************************************
    Author :guanjun
    Created Time :2016/2/19 14:25:19
    File Name :vijosp1130.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
    int x,y;
    };
    struct cmp{
    bool operator()(Node a,Node b){
    if(a.x==b.x) return a.y> b.y;
    return a.x>b.x;
    }
    };

    bool cmp(int a,int b){
    return a>b;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    ll f[1100],n;
    f[1]=1;
    f[2]=f[1]+1;
    f[3]=f[1]+1;
    f[4]=f[1]+f[2]+1;
    f[5]=f[1]+f[2]+1;
    f[6]=f[1]+f[2]+f[3]+1;
    for(int i=4;i<=1001;i++){
    int x=i/2;
    f[i]=0;
    for(int j=1;j<=x;j++){
    f[i]+=f[j];
    }
    f[i]++;
    }
    while(cin>>n){
    cout<<f[n]<<endl;
    }
    return 0;
    }

  • 0
    @ 2015-10-22 21:59:35

    var
    n,ans:longint;
    procedure go(t:longint);
    var
    i:longint;
    begin
    if t>0 then
    for i:=1 to t do
    inc(ans);
    for i:=1 to t do
    go(i div 2);
    end;
    begin
    readln(n);
    go(n div 2);
    writeln(ans+1);
    end.

  • 0
    @ 2015-09-10 16:17:40

    program numbercount;

    var n,ans:longint;

    procedure f(x:longint);
    var n:longint;
    begin
    n:=x div 2;
    while n>0 do begin
    inc(ans);
    f(n);
    dec(n);
    end;
    end;

    begin
    readln(n);
    ans:=1;
    f(n);
    writeln(ans);
    end.

信息

ID
1130
难度
2
分类
递推 点击显示
标签
递交数
7079
已通过
4174
通过率
59%
被复制
30
上传者