这题我一开始就想到数位dp了,其实好像也不是很难,但是自己写不出来。。。常规套路,f[i][j][k][t],从后往前填数,i位,j代表是否卡着上沿,k是现在有几个1,t是想要有几个。记忆化搜索就ok啦!

题干:

题目背景

众所周知,花神多年来凭借无边的神力狂虐各大 OJ、OI、CF、TC …… 当然也包括 CH 啦。
题目描述 话说花神这天又来讲课了。课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了。 花神的题目是这样的:设 sum(i)\text{sum}(i)sum(i) 表示 iii 的二进制表示中 的个数。给出一个正整数 NNN ,花神要问你 ∏i=1Nsum(i)\prod_{i=}^{N}\text{sum}(i)∏i=1N​sum(i) ,也就是 sum()∼sum(N)\text{sum}()\sim\text{sum}(N)sum()∼sum(N) 的乘积。
输入输出格式
输入格式: 一个正整数 N。 输出格式: 一个数,答案模 的值。 输入输出样例
输入样例#: 复制 输出样例#: 复制 说明 对于 % 的数据,N≤^

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(register int i = a;i <= n;++i)
#define lv(i,a,n) for(register int i = a;i >= n;--i)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
const int N = ;
const int mod = ;
ll n;
int x[N],cnt = ;
ll f[N][][N][N];
ll ans[N];
ll qpow(ll a,ll b)
{
ll tot = ;
while(b)
{
if(b & )
{
tot *= a;
tot %= mod;
}
a *= a;
a %= mod;
b >>= ;
}
return tot;
}
ll _f(int cur,int up,int tmp,int d)
{
if(!cur)
return tmp == d;
if(~f[cur][up][tmp][d])
return f[cur][up][tmp][d];
int lim = up ? x[cur] : ;
ll ret = ;
for(int i = ;i <= lim;++i)
{
ret += _f(cur - ,up && i == lim,tmp + (i == ),d);
}
return f[cur][up][tmp][d] = ret;
}
ll solve()
{
while(n)
{
x[++cnt] = n & ;
n >>= ;
}
for(int i = ;i <= ;i++)
{
memset(f,-,sizeof(f));
ans[i] = _f(cnt,,,i);
}
ll ret = ;
for(int i = ;i <= ;++i)
{
ret = ret * qpow(i,ans[i]) % mod;
}
}
int main()
{
read(n);
printf("%lld\n",solve());
}

P4317 花神的数论题 dp的更多相关文章

  1. DP,数论————洛谷P4317 花神的数论题(求1~n二进制中1的个数和)

    玄学代码(是洛谷题解里的一位dalao小粉兔写的) //数位DP(二进制)计算出f[i]为恰好有i个的方案数. //答案为∏(i^f[i]),快速幂解决. #include<bits/stdc+ ...

  2. P4317 花神的数论题 动态规划?数位DP

    思路:数位$DP$ 提交:5次(其实之前A过,但是调了调当初的程序.本次是2次AC的) 题解: 我们分别求出$sum(x)=i$,对于一个$i$,有几个$x$,然后我们就可以快速幂解决. 至于求个数用 ...

  3. 洛谷 P4317 花神的数论题 || bzoj3209

    https://www.lydsy.com/JudgeOnline/problem.php?id=3209 https://www.luogu.org/problemnew/show/P4317 设c ...

  4. Luogu P4317 花神的数论题

    也是一道不错的数位DP,考虑先转成二进制后再做 转化一下问题,考虑统计出\([1,n]\)中在二进制下有\(i\)个\(1\)的方案数\(cnt_i\),那么答案显然就是\(\prod i^{cnt_ ...

  5. 洛谷P4317 花神的数论题

    洛谷题目链接 数位$dp$ 我们对$n$进行二进制拆分,于是就阔以像十进制一样数位$dp$了,基本就是套模板.. 接下来是美滋滋的代码时间~~~ #include<iostream> #i ...

  6. 洛谷 P4317 花神的数论题(组合数)

    题面 luogu 题解 组合数 枚举有多少个\(1\),求出有多少种数 扫描\(n\)的每一位\(1\), 强制选\(0\)然后组合数算一下有多少种方案 Code #include<bits/s ...

  7. P4317 花神的数论题

    题目 洛谷 数学方法学不会%>_<% 做法 爆搜二进制下存在\(i\)位\(1\)的情况,然后快速幂乘起来 My complete code #include<bits/stdc++ ...

  8. P4317 花神的数论题,关于luogu题解粉兔做法的理解

    link 题意 设 \(\text{sum}(i)\) 表示 \(i\) 的二进制表示中 \(1\) 的个数.给出一个正整数 \(N\) ,求 \(\prod_{i=1}^{N}\text{sum}( ...

  9. 【洛谷】4317:花神的数论题【数位DP】

    P4317 花神的数论题 题目背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 题目描述 话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我 ...

随机推荐

  1. react.js 高阶组件----很简单的实例理解高阶组件思想

    调试代码之前,我设置了两个缓存 分别是username和content 在控制台console设置两个缓存代码 localStorage.setItem('username','老王')localSt ...

  2. 【收藏】下载Chrome商店插件的方法,万恶的gwd

    以下是下载离线插件包的方法: 第一步: 每个Google Chrome扩展都有一个固定的ID,例如https://chrome.google.com/webstore/detail/bfbmjmiod ...

  3. Codeforces917C. Pollywog

    $n \leq 1e8$个石头,$x \leq 8$个蝌蚪一开始在最左边$x$个石子,要跳到最右的$x$个,每次只能最左边的蝌蚪跳一次,一个石头不能站两个蝌蚪,跳可以跳$1到k,x \leq k \l ...

  4. PHP 常见问题2

    11.能够使 HTML 和 PHP 分离开使用的模板(1 分) 答: Smarty,Dwoo,TinyButStrong,Template Lite,Savant,phemplate,XTemplat ...

  5. POJ 2965 The Pilots Brothers' refrigerator【BFS+状压 Or 脑洞】

    题目链接: http://poj.org/problem?id=1753 题意: 给定冰箱门的开关情况,改变一个门则其所在行列的门都会发生改变,求出改变门的最少操作使得最终所有门都是打开状态. 代码: ...

  6. 学习日常笔记<day13>jsp加强

    1.jsp的内置对象(重点) 1.1什么是内置对象? 在jsp开发中,会频繁使用到一些现象 例如HttpSession,ServletContext,ServletContext,HttpServle ...

  7. java基础 3 Object通用方法(1)

    Object通用方法(1) clone: 浅复制    被复制对象的所有变量都含有与原对象相同的值,而所有对其他对象的引用仍然指向原来的对象,换言之,浅复制仅仅复                   ...

  8. 【python】搜索引擎方面的资料

    http://blog.csdn.net/hguisu/article/category/1230933

  9. RHEL 启动系统及故障排除

    一:Linux的启动过程: 开机加电自检->MBR引导(boot loader占446字节,分区列表64字节,magic占2字节)-->grub菜单(MBR是grub的第一个字段,第二个字 ...

  10. 2003 -Can't connection to mysql server on | navicat for mysql Access denied for user 'root'@''ip'(using password :yes)

    用本机windows上的Navicat for mysql链接虚拟机Linux的mysql数据库时,第一次连接的时候报的错误是 2003 -Can't connection to mysql serv ...