nas网站怎么做网站,网站建设横幅标语,网页版游戏网站,网站案例 网站建设传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你一个nnn#xff0c;问你有多少对0≤a≤b≤n0\le a\le b\le n0≤a≤b≤n满足S(a)S(b)S(a)S(b)S(a)S(b)。其中S(a)S(a)S(a)表示aaa的十进制各位数之和。
思路#xff1a;
显然的数位dpdpd…传送门
文章目录题意思路题意
给你一个nnn问你有多少对0≤a≤b≤n0\le a\le b\le n0≤a≤b≤n满足S(a)S(b)S(a)S(b)S(a)S(b)。其中S(a)S(a)S(a)表示aaa的十进制各位数之和。
思路
显然的数位dpdpdp一般的数位dpdpdp都是维护一个数这个无非就是维护两个数加一维状态就好啦。 定义f[pos][c][flag1][flag2]f[pos][c][flag1][flag2]f[pos][c][flag1][flag2]表示到了第pospospos位aaa与bbb的差值为cccflag1flag1flag1表示bbb是否能取到上界flag2flag2flag2表示aaa是否能取到上界。 让后就是裸的数位dpdpdp辣给差值加一个偏移量就好啦。
// Problem: Harmony Pairs
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/5671/H
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#includerandom
#includecassert
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].ltr[u].r)1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N210,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;string s;
int a[N],tot;
LL f[210][2010][2][2];LL dp(int pos,int c,int flag1,int flag2) {if(pos0) return c1000;if(f[pos][c][flag1][flag2]!-1) return f[pos][c][flag1][flag2];LL ans0;int xflag1? 9:a[pos];for(int i0;ix;i) {int yflag2? 9:i;for(int j0;jy;j) {ansdp(pos-1,cj-i,flag1||ix,flag2||jy);ans%mod;}}return f[pos][c][flag1][flag2]ans;
}LL solve() {tot0;for(int is.length()-1;i0;i--) a[tot]s[i]-0;return dp(tot,1000,0,0);
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);memset(f,-1,sizeof(f));cins;printf(%lld\n,solve());return 0;
}
/**/