洛谷 P4317 花神的数论题(组合数)
题面
题解
组合数
枚举有多少个\(1\),求出有多少种数
扫描\(n\)的每一位\(1\), 强制选\(0\)然后组合数算一下有多少种方案
Code
#include<bits/stdc++.h>
#define LL long long
#define RG register
using namespace std;
template<class T> inline void read(T &x) {
x = 0; RG char c = getchar(); bool f = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
x = f ? -x : x;
return ;
}
template<class T> inline void write(T x) {
if (!x) {putchar(48);return ;}
if (x < 0) x = -x, putchar('-');
int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 55, Mod = 10000007;
LL C[N][N], cnt, a[N];
inline LL Pow(int a, LL b) {
LL s = 1;
for (LL x = a; b; b >>= 1, x = x*x%Mod) if (b&1) s = s*x%Mod;
return s;
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
for (int i = 0; i <= 50; i++) C[i][i] = C[i][0] = 1;
for (int i = 2; i <= 50; i++)
for (int j = 1; j < i; j++)
C[i][j] = C[i-1][j-1]+C[i-1][j];
LL n; read(n);
for (int i = 50; i >= 0; i--) {
if ((n>>i)&1) {
for (int j = 1; j <= i; j++)
a[j+cnt] += C[i][j];//至少选1个的方案
a[++cnt]++;//不选的方案(必须分开算,不然会有重复计算)
}
}
LL ans = 1;
for (int i = 1; i <= 50; i++)
ans = ans*Pow(i, a[i])%Mod;
printf("%lld\n", ans);
return 0;
}
洛谷 P4317 花神的数论题(组合数)的更多相关文章
- DP,数论————洛谷P4317 花神的数论题(求1~n二进制中1的个数和)
玄学代码(是洛谷题解里的一位dalao小粉兔写的) //数位DP(二进制)计算出f[i]为恰好有i个的方案数. //答案为∏(i^f[i]),快速幂解决. #include<bits/stdc+ ...
- 洛谷P4317 花神的数论题
洛谷题目链接 数位$dp$ 我们对$n$进行二进制拆分,于是就阔以像十进制一样数位$dp$了,基本就是套模板.. 接下来是美滋滋的代码时间~~~ #include<iostream> #i ...
- 洛谷 P4317 花神的数论题 || bzoj3209
https://www.lydsy.com/JudgeOnline/problem.php?id=3209 https://www.luogu.org/problemnew/show/P4317 设c ...
- [BZOJ3209]花神的数论题 组合数+快速幂
3209: 花神的数论题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2498 Solved: 1129[Submit][Status][Disc ...
- P4317 花神的数论题
题目 洛谷 数学方法学不会%>_<% 做法 爆搜二进制下存在\(i\)位\(1\)的情况,然后快速幂乘起来 My complete code #include<bits/stdc++ ...
- P4317 花神的数论题 dp
这题我一开始就想到数位dp了,其实好像也不是很难,但是自己写不出来...常规套路,f[i][j][k][t],从后往前填数,i位,j代表是否卡着上沿,k是现在有几个1,t是想要有几个.记忆化搜索就ok ...
- Luogu P4317 花神的数论题
也是一道不错的数位DP,考虑先转成二进制后再做 转化一下问题,考虑统计出\([1,n]\)中在二进制下有\(i\)个\(1\)的方案数\(cnt_i\),那么答案显然就是\(\prod i^{cnt_ ...
- P4317 花神的数论题 动态规划?数位DP
思路:数位$DP$ 提交:5次(其实之前A过,但是调了调当初的程序.本次是2次AC的) 题解: 我们分别求出$sum(x)=i$,对于一个$i$,有几个$x$,然后我们就可以快速幂解决. 至于求个数用 ...
- P4317 花神的数论题,关于luogu题解粉兔做法的理解
link 题意 设 \(\text{sum}(i)\) 表示 \(i\) 的二进制表示中 \(1\) 的个数.给出一个正整数 \(N\) ,求 \(\prod_{i=1}^{N}\text{sum}( ...
随机推荐
- Mysql 设置外部访问
mysql> use mysql; mysql> GRANT ALL ON *.* TO user@' WITH GRANT OPTION; mysql -h172. -uuser -p1 ...
- java 从jsp页面传集合给controller
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- Linux yum失败解决
Linux yum失败解决 问题: 在CentOS 5.5中需要使用yum安装程序,出现错误: There was a problem importing one of the Python modu ...
- 使用 dataview 组件制作一览表
来自于<sencha touch权威指南>第八章,183页左右 ----------------------------------- 一.app.js代码: Ext.require([' ...
- numpy.loadtxt() 出现codecError_____ Excel 做矩阵乘法
1) 用 numpy读入csv文件是报错 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal m ...
- 关于Flag 老是忘掉的东西
OrderState enums = OrderState.CustomerCanceled | OrderState.CustomerOrdered | OrderState.CustomerQue ...
- Jquery Call ,apply,callee
//call function A() { name = "abc"; this.ShowName = function (val) { alert(name + ",& ...
- Ubuntu不能上网解决办法
一.设置IP.网关.DNS 新安装的Ubuntu系统ifconfig后发现没有ip,所以要设置IP.网关.DNS等,编辑 /etc/networking/interfases sudo vi /et ...
- 【连载】redis库存操作,分布式锁的四种实现方式[二]--基于Redisson实现分布式锁
一.redisson介绍 redisson实现了分布式和可扩展的java数据结构,支持的数据结构有:List, Set, Map, Queue, SortedSet, ConcureentMap, L ...
- 小规模kvm宿主机管理-webvirtmgr安装
1.前言WebVirtMgr是近两年来发展较快,比较活跃,非常清新的一个KVM管理平台,提供对宿主机和虚机的统一管理,它有别于kvm自带的图形管理工具(virtual machine manager) ...