CF1073E Segment Sum 自闭了
CF1073E Segment Sum
题意翻译
给定\(K,L,R\),求\(L\)~\(R\)之间最多不包含超过\(K\)个数码的数的和。
\(K<=10,L,R<=1e18\)
我 写 晕 了
我 自 闭 了


根本不知道自己在写什么????
告辞。。。
错误Code:
#include <cstdio>
#define ll long long
const ll mod=998244353;
ll dp[2][20][1<<10],cnt[2][20][1<<10],po[20],l,r;
int k;
void init()
{
po[0]=1;
for(int i=1;i<=18;i++) po[i]=po[i-1]*10%mod;
cnt[0][0][0]=1;
for(int i=1;i<=18;i++)
for(int s=0;s<1<<10;s++)
{
for(int j=1;j<=9;j++)
if(s>>j&1)
{
int t=(1<<j)^s;
(cnt[1][i][s]+=(cnt[0][i-1][s]+cnt[1][i-1][s]
+cnt[0][i-1][t]+cnt[1][i-1][t]))%=mod;
}
int t=s^1;
if(s&1)
(cnt[0][i][s]+=(cnt[0][i-1][s]+cnt[1][i-1][s]
+cnt[0][i-1][t]+cnt[1][i-1][t]))%=mod;
}
for(int i=1;i<=18;i++)
for(int s=0;s<1<<10;s++)
{
for(int j=1;j<=9;j++)
if(s>>j&1)
{
int t=(1<<j)^s;
ll tmp0=(cnt[0][i-1][s]+cnt[1][i-1][s]
+cnt[0][i-1][t]+cnt[1][i-1][t])%mod;
ll tmp1=(dp[0][i-1][s]+dp[1][i-1][s]
+dp[0][i-1][t]+dp[1][i-1][t])%mod;
(dp[1][i][s]+=(tmp1+j*po[i-1]%mod*tmp0))%=mod;
}
if(s&1)
{
int t=s^1;
ll tmp1=(dp[0][i-1][s]+dp[1][i-1][s]
+dp[0][i-1][t]+dp[1][i-1][t])%mod;
dp[0][i][s]=tmp1;
}
}
}
int bit[20];
ll solve(ll d)
{
int rt=0;
for(ll i=d;i;i/=10) bit[++rt]=i%10;
int cho=0;//高位已选状态
ll res=0,ans=0;//高位剩余
for(int i=rt;i;i--)
{
for(int s=0;s<1<<10;s++)
{
int ct=0;
for(int t=s;t;t>>=1) ct+=t&1;
if(ct>k+1) continue;
if(s&1)
{
int t=s^1;
ll tmp1=(dp[0][i-1][s]+dp[1][i-1][s]
+dp[0][i-1][t]+dp[1][i-1][t])%mod;
ans+=tmp1;
}
if(ct>k) continue;
for(int j=1;j<bit[i]+(i==1);j++)//高位选填
if((s>>j&1)&&((s|cho)==s))
{
int t=(1<<j)^s;
ll tmp0=(cnt[0][i-1][s]+cnt[1][i-1][s]
+cnt[0][i-1][t]+cnt[1][i-1][t])%mod;
ll tmp1=(dp[0][i-1][s]+dp[1][i-1][s]
+dp[0][i-1][t]+dp[1][i-1][t])%mod;
(ans+=tmp1+tmp0*(j+res)%mod*po[i-1]%mod)%=mod;
}
}
res=(res+bit[i])*10%mod;
cho|=1<<bit[i];
}
return ans;
}
int main()
{
scanf("%lld%lld%d",&l,&r,&k);
init();
printf("%lld\n",((solve(r)-solve(l-1))%mod+mod)%mod);
return 0;
}
updata2019.2.9
写了好几个月,终于肝出来了
Code:
#include <cstdio>
#include <cstring>
#define ll long long
const int mod=998244353;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
#define mul(a,b) (1ll*(a)*(b)%mod)
int po[20],bit[20],len,k;
struct node
{
int val,cnt;
node(){}
node(int v,int c){val=v,cnt=c;}
node friend operator +(node a,node b){return node(add(a.val,b.val),add(a.cnt,b.cnt));}
}dp[20][1<<10];
node dfs(int pos,int sta,int lead,int lim)//前导0和最高位限制
{
int cnt=0;
for(int i=0;i<10;i++) cnt+=sta>>i&1;
if(cnt>pos) return node(0,0);
if(!pos) return node(0,1);
if(!lim&&!lead&&~dp[pos][sta].val) return dp[pos][sta];
node ret=node(0,0),bee;
if(lead) ret=ret+dfs(pos-1,sta,lead,lim&&!bit[pos]);
else if(sta&1) ret=ret+dfs(pos-1,sta,lead,lim&&!bit[pos])+dfs(pos-1,sta^1,lead,lim&&!bit[pos]);
for(int i=1,up=lim?bit[pos]:9;i<=up;i++)
if(sta>>i&1)
{
bee=dfs(pos-1,sta,0,lim&&i==up)+dfs(pos-1,sta^(1<<i),0,lim&&i==up);
ret=ret+bee;
ret.val=add(ret.val,mul(bee.cnt,mul(i,po[pos-1])));
}
return !lim&&!lead?dp[pos][sta]=ret:ret;
}
int cal(ll x)
{
len=0;while(x) bit[++len]=x%10,x/=10;
memset(dp,-1,sizeof dp);int ans=0;
for(int s=0;s<1<<10;s++)
{
int cnt=0;
for(int i=0;i<10;i++) cnt+=s>>i&1;
if(cnt<=k) ans=add(ans,dfs(len,s,1,1).val);
}
return ans;
}
int main()
{
ll l,r;
scanf("%lld%lld%d",&l,&r,&k);
po[0]=1;for(int i=1;i<=18;i++) po[i]=mul(po[i-1],10);
printf("%d\n",add(cal(r),mod-cal(l-1)));
return 0;
}
CF1073E Segment Sum 自闭了的更多相关文章
- CF1073E Segment Sum 解题报告
CF1073E Segment Sum 题意翻译 给定\(K,L,R\),求\(L~R\)之间最多不包含超过\(K\)个数码的数的和. \(K\le 10,L,R\le 10^{18}\) 数位dp ...
- CF1073E Segment Sum
数位DP,求[L,R]区间内所有"数字内包含的不同数码不超过k个的数字"之和.在状态上加一维状态压缩表示含有的数码集合.一开始读错题以为是求数字的个数.读对题之后调了一会儿. #i ...
- Codeforces 1073 E - Segment Sum
E - Segment Sum 思路: 数位dp 我们平时做的数位dp都是求满足条件的数的个数, 这里要求满足条件的数的和 只要在原来的基础上求每一位的贡献就可以了,所以传参数时要传两个 代码: #p ...
- Educational Codeforces Round 53 E. Segment Sum(数位DP)
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...
- CodeForces - 1073E :Segment Sum (数位DP)
You are given two integers l l and r r (l≤r l≤r ). Your task is to calculate the sum of numbers from ...
- E. Segment Sum(数位dp)
题意:求一个区间内满足所有数位不同数字个数小于K的数字总和.比如:k=2 1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足. 我们可以使用一个二进制的数 ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum
https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...
- CF 1073 E. Segment Sum
https://codeforces.com/problemset/problem/1073/E 题意:[l,r]中,出现0—9数字的种类数不超过k的数的和 dp[i][j][0/1] 表示 dfs到 ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)
题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...
随机推荐
- TW实习日记:第20-21天
为什么上周五没写呢,因为上周五一直在熟悉业务流程...根本不会写一些复杂的业务代码,因为没有业务流程图!!!在学校的上需求分析和UML建模课的时候,还有软件工程课的时候,想着这都什么鬼啊,听来干嘛,写 ...
- Java学习 · 初识 面向对象深入一
面向对象深入 1.面向对象三大特征 a) 继承 inheritance 子类可以从父类继承属性和方法 子类可以提供自己的属性方法 b) 封装 encapsulation 对外隐藏某些属性和方法 对外公 ...
- some Commands OF CONSOLE
不可避免地使用console,一旦与电脑打交道:入口就是help,而很多行就直接过掉了,却不能看到需要的地方,在那里停下来,实际是需要使用more less grep等 在windows中,使用di ...
- Python3 Tkinter-Place
1.绝对坐标 from tkinter import * root=Tk() lb=Label(root,text='hello Place') lb.place(x=0,y=0,anchor=NW) ...
- 五:ResourceManager High Availability RM 高可用
RM有单点失败的风险,但是可以做HA. RMs HA通过master/standby这种结构实现,一个master是active的,其它standby是inactive的.可能通过命令行切换主备节点 ...
- df -h 卡住
mount 检查是否有挂载nfs的分区 网络挂载 如果有请umount -l /相应目录 umount -l 10.74.82.205:/letv/fet/nfs ...
- C语言实验——时间间隔
Description 从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示. 如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时 ...
- Thunder团队第六周 - Scrum会议1
Scrum会议1 小组名称:Thunder 项目名称:i阅app Scrum Master:王航 工作照片: 参会成员: 王航(Master):http://www.cnblogs.com/wangh ...
- 《梦断代码Dreaming In Code》阅读笔记(三)
最后这几章感觉上更多是从软件完成整体上来讲的.比如说技术.方法等. 在我看来,其实一个团队一直坚持一种好的.先进的方法是不可少的.如果一个优秀的团队刚愎自用,只随着成员们喜好发展,那不能长久.比如说, ...
- lintcode-13-字符串查找
字符串查找 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始).如果不存在,则返回 -1. 说明 ...