Meaningless Sequence Gym - 102832D

题意:

给你n和c,an的公式如下图

让你求a0+…an的和,mod 1e9+7

题解:

训练时推了好一阵子才和队友推出
我看网上正解为:
一个数的大小与它的二进制表示中的1的个数有关
a=c(二进制中1的个数)
问题就变成了转化为求所有数中1的个数,
dp[i][j]为考虑i~n位,有j个1的情况有多少种,然后数位dp跑,详细可以看代码

训练时我们是找到了规律,我通过列出1~20的ai答案,发现规律,比如7,对应的二进制是111,那么它就等于去掉最高位剩下部分对应的数乘c,111去掉最高位就是011,也就是3,而3对应的是c2,所以7就是c3,(当然3也可以通过这个方法得到),边界就是00对应1,01对应c
而且还有规律,第一位+第二位的和乘以c就是第三位加第四位的和,前四位的和乘c,就是5到8位的和,也就是sum=(c+1),sum+=sum*c,看几轮

根据这些性质我们就可以算出答案,比如1000(二进制),我们可以计算出111部分的答案,就是sum=(c+1),进行两轮的sum+=sum * c,然后让1100减去111,得到0101,重复这个过程,先计算11的答案,然后减11,一值重复,直到最后位,最后得到答案(不是很明白的可以看看代码)

代码:

数位dp

#include <cstdio>
#include <algorithm>
#include <cstring>using namespace std;const int mod = 1e9 + 7;
typedef long long ll;
char a[3005];
int n;
ll dp[3005][3005],c;ll qpow(ll x,ll n) {ll res = 1;if(n == -1) return 0;while(n) {if(n & 1) {res = res * x % mod;}x = x * x % mod;n >>= 1;}return res;
}ll dfs(int len,int sum,bool limit) {if(sum < 0) return 0;if(sum > n - len + 1) return 0;if(len == n + 1) {return sum == 0;}if(!limit && dp[len][sum] != -1) return dp[len][sum];int up = (limit ? (a[len] - '0') : 1);ll ans = 0;for(int i = 0;i <= up;i++) {ans += dfs(len + 1,sum - (i == 1),limit && i == up);ans %= mod;}return limit ? ans : dp[len][sum] = ans;
}int main() {scanf("%s%lld",a + 1,&c);n = strlen(a + 1);memset(dp,-1,sizeof(dp));ll ans = 0;for(int i = 0;i <= n;i++) {ll num = dfs(1,i,true);ans = (ans + num * qpow(c,i) % mod) % mod;}printf("%lld\n",ans);return 0;
}

规律递推代码:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
const int mod=1e9+7;
ll poww(ll a,ll b){ll ans=1;while(b){if(b&1)ans*=a%mod;a*=a%mod;b>>=1;}return ans%mod;
}
string s;ll c;
ll cal(int len){ll sum=(c+1)%mod;for(int i=1;i<len;i++){sum=(sum+sum*c%mod)%mod;}return sum;
}int main(){cin>>s>>c;ll sum=0;int len=s.length();if(s[len-1]=='0'){sum=1;}else sum=c+1;for(int i=len-2;i>=0;--i){if(s[i]!='0'){sum=sum*c%mod;sum=(sum+cal(len-i-1))%mod;}
//      cout<<sum<<endl;}
//  sum+=cal(len-1);
//  for(int i=0;i<len;i++){//      if(n[i]=='1')
//          sum+=cal(len-i-1);
//  }cout<<sum;return 0;
}

Meaningless Sequence Gym - 102832D相关推荐

  1. 2020CCPC长春

    2020CCPC长春 题号 题目 难度 知识点 A Krypton 签到 01背包 B The Tortoise and the Hare C Quantum Geometry D Meaningle ...

  2. HRBU_20211122训练

    A - Krypton 题意: 你有n元,你打算往游戏里进行充值,游戏中有充值优惠,首次充值达到某个金额时,你就会获得一定的返利,具体见下图,问当你充值n元时,最后你能获得的最多的点券数? 做法: 模 ...

  3. 2020CCPC长春 部分题解

    D Meaningless Sequence (找规律)   解法一: 要推公式找规律是很难推的,所以直接打表可以发现规律: SUM[2^n,2^(n+1) ) = c*(c+1)^n         ...

  4. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  5. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

  6. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. Codeforces Gym 100463A Crossings 逆序数

    Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...

  8. 【论文阅读】Decision Transformer: Reinforcement Learning via Sequence Modeling

    [论文阅读]Decision Transformer: Reinforcement Learning via Sequence Modeling 1 本文解决了什么问题? 本文将强化学习抽象为一个序列 ...

  9. Correct Bracket Sequence Editor

    E. Correct Bracket Sequence Editor time limit per test           2 seconds memory limit per test    ...

最新文章

  1. MySQL新建数据库+用Navicat查看MySQL的方法
  2. angular 注入器配置_angular依赖注入
  3. 交叉熵损失(Cross Entropy Loss)计算过程
  4. 为什么一定要回家?因为我们是中国人
  5. 1.5 matlab常量与变量
  6. Reactor by Example--转
  7. datagridview输入字符串的格式不正确_Python3试学:输入和输出(1)
  8. 判断点是否在三角形内
  9. 阿里云的RDS 查看binlog日志的方法
  10. mybatis DATE_FORMAT 格式化时间输出
  11. linux使用脚本执行vim命令行,linux – 如何通过shell脚本执行vim命令
  12. java-php-python-ssm幼儿园管理系统计算机毕业设计
  13. 内核流浪猫流浪狗宠物领养平台H5源码
  14. 学习笔记(六):C++串口连接
  15. poi 操作word文档,poi 向word插入图片,poi 向word入表格,XWPFParagraph 分段,XWPFDocument单元格合并,XWPFDocument 操作word
  16. C# 实现实时网速
  17. Rust Reqwest 学习
  18. Liunx实现超级签名详细攻略(一)超级签名简介
  19. TX2 用文件IO的方式操作GPIO
  20. 瀑布模型与“V”模式开发模型有何异同?

热门文章

  1. 学霸真的比学渣更讨女孩子欢心吗?
  2. 43秒处竟惊现刘强东!印度动作大片《WAR》终极预告曝光
  3. 熬夜族又一噩耗:“早死”风险更高!
  4. java搜索string_java – 在数组列表中搜索最常见的String
  5. qt显示echart_Qt配置,载入html,Echart, 交互
  6. goahead如何使用cgi服务_QQ如何设置使用代理服务器?
  7. python的所有库_Python 常用库
  8. matlab dy,高手,请问用matlab如何解下面方程:y*Dy=a+b*y;我的计算结果里面含有wrightOmega ,怎样解出一般解?...
  9. ab压力测试_Apache ab压力测试的知识点
  10. 不是python文件处理seek()方法的参数是_python文件操作seek()偏移量,读取指正到指定位置操作...