1018: Give me the answer

时间限制: 1 Sec  内存限制: 32 MB
提交: 55  解决: 15
[提交][状态][讨论版][命题人:外部导入]

题目描述

Farmer John commanded his cows to search for different sets of numbers that sum to a given number.
The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that
sum to 7:
1) 1+1+1+1+1+1+1
2) 1+1+1+1+1+2
3) 1+1+1+2+2
4) 1+1+1+4
5) 1+2+2+2
6) 1+2+4
Help FJ count all possible representations for a given integer N (1 <= N <= 1 ,000,000)

输入

The first line of the input contains the number of test cases in the file. And t he first line of each case
contains one integer numbers n

输出

For each test case, output a line with the ans % 1000000000.

样例输入

1
7

样例输出

6
#include<stdio.h>
#define MAX 1000010
int a[MAX];
int main()
{
int n, m, i;
a[1] = 1;
a[2] = 2;
for(i = 3; i <= MAX; ++i)
{
if(i & 1)
a[i] = a[i - 1] % 1000000000;
else
a[i] = (a[i - 1] + a[i / 2]) % 1000000000;
}
scanf("%d", &n);
while(n--)
{
scanf("%d", &m);
printf("%d\n", a[m]);
}
return 0;
}

  

 

1018: Give me the answer的更多相关文章

  1. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  2. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  3. A - Divide it! CodeForces - 1176A

    题目: You are given an integer nn. You can perform any of the following operations with this number an ...

  4. CodeForces - 1176A Divide it! (模拟+分类处理)

    You are given an integer nn. You can perform any of the following operations with this number an arb ...

  5. Codeforces1176A(A题)Divide it!

    Divide it! You are given an integer nn. You can perform any of the following operations with this nu ...

  6. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  7. 【LEETCODE】53、数组分类,简单级别,题目:989、674、1018、724、840、747

    真的感觉有点难... 这还是简单级别... 我也是醉了 package y2019.Algorithm.array; import java.math.BigDecimal; import java. ...

  8. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  9. PAT A 1018. Public Bike Management (30)【最短路径】

    https://www.patest.cn/contests/pat-a-practise/1018 先用Dijkstra算出最短路,然后二分答案来验证,顺便求出剩余最小,然后再从终点dfs回去求出路 ...

随机推荐

  1. 1 Groovy

    1.1  什么是Groovy? groovy 是一个弱类型,动态语言,并且运行在JVM之上.它与java联系紧密.它是一个功能丰富和友好的java语言. Groovy源代码,通过Groovy编译器编译 ...

  2. Gone Fishing

    原题网址 代码已经写出来了,自己测试的时候没有问题,提交上去之后反馈了我一个Runtime error  一口老血啊! 找了半天还是没找到可能越界啊啥的地方 import java.util.Scan ...

  3. Yii2的框架笔记整理

    1 .request的获取方式 $request = Yii::$app->request; 2. get参数的获取方式 $id = $request->get('id',1);获取get ...

  4. CSS十问——好奇心+刨根问底=CSSer(转)

    最近有时间,想把酝酿的几篇博客都写出来,今天前端小学生带着10个问题,跟大家分享一下学习CSS的一些体会,我觉得想学好CSS,必须保持一颗好奇心和刨根问底的劲头,而不是复制粘贴,得过且过.本人能力有限 ...

  5. Flag-2019上半年

    1.坚持做博客记录,把日常学习到的技能以日记的形势进行呈现,每周进行总结: 2.2月底完成吴老师的机器学习视频课程: 3.6月底完成吴老师的深度学习视频课程: 相信自己,可以的,半年后见!

  6. inventor安装失败怎样卸载安装inventor 2014?

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  7. Homebrew 配置

    使用ruby脚本安装完成homebrew之后, 需要配置三个源以及添加一些环境变量 1. export HOMEBREW_NO_AUTO_UPDATE=true # 不自动检查更新 2. cd $(b ...

  8. .net iis6中配置伪静态

    1.右键点击 要设置网站的网站 2.属性 ——>主目录 ——>配置——> 3.如右侧窗口,找到 .aspx 扩展名——>编辑——>复制 可执行文件的路径——>关闭 ...

  9. 随机练习:C#实现维吉尼亚加密与解密(解密前提为已知密匙)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. 利用自定义特性实现List的多属性排序

    知道linq有order by的功能,但是还是动手研究了一下,算是多实践实践反射.这篇算是笔记,直接上代码: using System; using System.Collections.Concur ...