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 ...
随机推荐
- JDK11源码分析之集合类(一)----HashMap
一,首先需要拉取JDK11源码: 方便起见我给出芋道源码作者已经拉取好的openJDK11的GitHub地址只需要fork一下克隆到本地导入IDEA中就可以对源码分析了: https://github ...
- GCC的函数声明问题
Thinking in C++ 第四章 GCC 不需要再MAIN函数前声明 编译也能通过. G++不行.
- 临时笔记 Protection
如果操作系统不使用处理器的多任务机制,它仍然需要为栈创建至少一个TSS 当程序通过调用门改变特权级的时候,处理器执行下面的步骤切换栈,并且执行被调用的程序在新的特权级 1. 使用目标代码段的DPL从T ...
- python 需求分析
第三章: 需求分析需求分析任务: ??? 功能分析性能分析EG: 相应时间.主存容量.磁盘容量.安全性.等可靠性和可用性出错处理需求系统发现错误时采取的行动,主要在系统关键部分设置接口需求用户接口.硬 ...
- 扩展 IHttpModule
上篇提到请求进入到System.Web后,创建完HttpApplication对象后会执行一堆的管道事件,然后可以通过HttpModule来对其进行扩展,那么这篇文章就来介绍下如何定义我们自己的mod ...
- 0.ssm web项目中的遇到的坑
1.自定义的菜单,href为项目的相对路径,即: : 点击一个菜单,后再点击另一个菜单,然后发现浏览器地址栏的链接是在上一个链接后面拼接的,也就报错了. 解决办法: 每一个菜单的href前增加&quo ...
- 09C++指针
指针 6.1 指针的概念 请务必弄清楚一个内存单元的地址与内存单元的内容这两个概念的区别.在程序中一般是通过变量名来对内存单元进行存取操作的.其实程序经过编译以后已经将变量名转换为变量的地址,对变量值 ...
- 【原】CentosDocker安装(一)
CentosDocker安装 来源:https://www.runoob.com/docker/centos-docker-install.html 1.前提条件 目前,CentOS 仅发行版本中的内 ...
- python circle nested
#!/usr/bin/python # -*- coding:utf- -*- # @filename: tmp2 # @author:vickey # @date: // : def circle_ ...
- pymouse pykeyboard
import time from pymouse import PyMouse from pykeyboard import PyKeyboard import re import win32clip ...