【题意】将一个数用二进制数表示,求一共有多少种表示方法。

【分析】思路一:完全背包

【代码】

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include<ctime>
using namespace std;
const int INF=0x3fffffff,maxn=1e5+40;
const int mod=1000000;
const int total=2000050;
int f[total];
int main (void)
{
    int T,temp;
    f[0]=1;
    scanf("%d",&T);
    for(int i=0;i<=20;i++)//2^20<total<2^21
        for(int j=(1<<i);j<total;j++)
            f[j]+=f[j-(1<<i)]%mod;
   while(T--)
   {
       scanf("%d",&temp);
       printf("%d\n",f[temp]%mod);
   }
}

代码在zoj上AC,但是在soj上就一直TLE,改了好久才勉强AC........渣哭

思路二:看了别人的博客,可以用递推思想,从二进制数的角度,任何一个数都可以由他前一个数+1表示,但如果该数n是偶数,那么他还可以由他的一半n/2表示,即将n/2左移一位

【代码】

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include<ctime>
using namespace std;
const int INF=0x3fffffff,maxn=1e5+40;
const int mod=1000000;
const int total=2000050;
int f[total];
int main (void)
{
int T,num;
f[0]=1;
for(int i=0;i<total;i++)
{
if(i%2==0)
f[i]=(f[i/2]+f[i-1])%mod;
else
f[i]=f[i-1]%mod;
}
scanf("%d",&T);
while(T--)
{
scanf("%d",&num);
printf("%d\n",f[num]);
}
}

SOJ 2785_Binary Partitions的更多相关文章

  1. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  2. 【贪心】SOJ 13983

    SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...

  3. Partitioning & Archiving tables in SQL Server (Part 2: Split, Merge and Switch partitions)

    Reference: http://blogs.msdn.com/b/felixmar/archive/2011/08/29/partitioning-amp-archiving-tables-in- ...

  4. Rotate partitions in DB2 on z

    Rotating partitions   You can use the ALTER TABLE statement to rotate any logical partition to becom ...

  5. How to choose the number of topics/partitions in a Kafka cluster?

    This is a common question asked by many Kafka users. The goal of this post is to explain a few impor ...

  6. rabbitmq之partitions

    集群为了保证数据一致性,在同步数据的同时也会通过节点之间的心跳通信来保证对方存活.那如果集群节点通信异常会发生什么,系统如何保障正常提供服务,使用何种策略回复呢? rabbitmq提供的处理脑裂的方法 ...

  7. ADF_Database Develop系列2_设计数据库表之Table Partitions/Create Users/Generate DDL

    2013-05-01 Created By BaoXinjian

  8. PostgreSQL Partitions

    why we need partitions The first and most demanding reason to use partitions in a database is to inc ...

  9. mypc--------------->lspci,lsusb,meminfo cpuinfo ioports filesystems interrupts mounts net partitions pagetypeinfo slabinfo timer_list uptime version zoneinfo 等配置信息

    [user@username home]$ lspci00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Contro ...

随机推荐

  1. Spring---AOP注解开发&jdbc模板&Spring事务管理

    一.AOP注解开发 此处需要回忆一遍AOP的概念.简单的来说,AOP就是利用动态代理技术,做到不触动源代码但却扩展了功能.那么就需要一个被扩展的对象和一个“新的功能”,例如说给某类的saveUser方 ...

  2. Android习惯--Activity启动方法

    public void Text extends Activity{ public void static actionStart(Context context, int i, String str ...

  3. myeclipse 跟踪struts 源码失败

    解决办法: 找到工程jar包所在的位置,点击右键:properties 点击external folder 找到  这个包下的src文件夹 导入之后, 源码会变色

  4. ios开发介绍

    iOS开发概述 •什么是IOS •什么是IOS开发 •为什么要选择IOS开发 •学习IOS开发的准备   1.什么是iOS   •iOS是一款由苹果公司开发的操作系统(OS是Operating Sys ...

  5. 迅为I.MX6开发板工业级嵌入式开发平台

    迅为-i.MX6开发板是是基于ARM Cortex™-A9架构的高扩展性多核系列应用处理器, i.MX6系列芯片而且根据应用场合的不同,提供了可供选择的单核.双核和四核产品供客户选择.i.MX6系列的 ...

  6. mycat+ mysql集群 分库分表

    mycat介绍Mycat数据库分库分表中间件国内最活跃的.性能最好的开源数据库中间件!Mycat关键特性关键特性支持SQL92标准支持MySQL.Oracle.DB2.SQL Server.Postg ...

  7. 用宿主机创建一个容器bind命令的应用

    先创建一个网页目录 [root@docker ~]# mkdir /app/wwwroot -p 用bind运行,源目录为刚才创建的 [root@docker ~]# docker run -itd ...

  8. sqlserver 创建索引 物化 视图

    索引视图: create view  Test WITH SCHEMABINDING as select Id, Name from [dbo].[InterfaceCallSetting]creat ...

  9. vlmcsd-1111-2017-06-17

    Source and binaries: http://rgho.st/6c6R7RwMZ   全部编译好了 https://www.upload.ee/files/7131474/vlmcsd-11 ...

  10. VMware12 download

    下载地址:http://filehippo.com/zh/download_vmware-workstation-pro/ 许可证地址:http://www.zdfans.com/5928.html