SOJ 2785_Binary Partitions
【题意】将一个数用二进制数表示,求一共有多少种表示方法。
【分析】思路一:完全背包
【代码】
#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的更多相关文章
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- 【贪心】SOJ 13983
SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...
- 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- ...
- Rotate partitions in DB2 on z
Rotating partitions You can use the ALTER TABLE statement to rotate any logical partition to becom ...
- 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 ...
- rabbitmq之partitions
集群为了保证数据一致性,在同步数据的同时也会通过节点之间的心跳通信来保证对方存活.那如果集群节点通信异常会发生什么,系统如何保障正常提供服务,使用何种策略回复呢? rabbitmq提供的处理脑裂的方法 ...
- ADF_Database Develop系列2_设计数据库表之Table Partitions/Create Users/Generate DDL
2013-05-01 Created By BaoXinjian
- PostgreSQL Partitions
why we need partitions The first and most demanding reason to use partitions in a database is to inc ...
- 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 ...
随机推荐
- MyEclipse开启Jquery智能提示
myeclipse 增加javascript提示和jquery提示等不用安装插件自带功能 (对着需要提示的项目右键,点击properties) 不行的话就得安装插件: http://www.spket ...
- call方法的使用bug--参数undefined
call/apply是函数原型定义的方法(Function.prorotype),在使用时要注意第一个形参(args[0]),一定是指向函数所要挂载的上下文对象--context,若对象非必须,则要将 ...
- MySQL多表
一.外键 1.外键:链接两张表的字段,通过主表的主键和从表的外键来描述主外键关系,呈现的是一对多的关系.例如:商品类别(一)对商品(多),主表:商品类别表,从表:商品表. 2.外键的特点:从表外键的值 ...
- fullpagejs实现的拥有header和foooter的全屏滚动demo/fullpage footer
fullpagejs实现的拥有header和foooter的全屏滚动, 技术要点:给section元素加fp-auto-height类, <!DOCTYPE html> <html ...
- R Programming week 3-Loop functions
Looping on the Command Line Writing for, while loops is useful when programming but not particularly ...
- java-IO操作性能对比
在软件系统中,IO速度比内存速度慢,IO读写在很多情况下会是系统的瓶颈. 在java标准IO操作中,InputStream和OutputStream提供基于流的IO操作,以字节为处理单位:Reader ...
- IE主页被恶意修改处理办法
HKEY_USERS/.DEFAULT/Software/Policies/Microsoft/Internet Explorer/Control Panel 下的DWORD值“homepage”的键 ...
- 优雅的创建map/list集合
带值的集合的创建 String[] a = {"1","2","3","4"}; boolean q = ArrayUt ...
- day23-1 isinstance、issubclass和反射
目录 isinstance和issubclass 反射(hasattr,getattr,setattr,delattr) isinstance和issubclass isinstance(obj,cl ...
- TensorFlow低阶API(一)—— 简介
简介 本文旨在知道您使用低级别TensorFlow API(TensorFlow Core)开始编程.您可以学习执行以下操作: 管理自己的TensorFlow程序(tf.Graph)和TensorFl ...