好朋友 题解

好朋友

https://ac.nowcoder.com/acm/problem/19327

统计0的个数,再判断有没有前导0,如果出现了007就记录,然后用相应的四位数组进行记忆化,比较常规的数位dp

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[20];
int f[20][20][2][2];
int dp(int pos,int num0,bool h007,bool have,bool flag)
{
    if(pos==0) return h007;
    if(flag&&f[pos][num0][h007][have]!=-1) return f[pos][num0][h007][have];
    int x=flag?9:a[pos];
    int ans=0;
    for(int i=0;i<=x;i++)
    {
        ans += dp(pos - 1, num0 + (have && i == 0), h007||(num0>=2&&i==7), i || have,flag||i<x);
    }
    if(flag) f[pos][num0][h007][have]=ans;
    return ans;
}
int cul(int x)
{
    int pos=0;
    while(x)
    {
        a[++pos]=x%10;
        x/=10;
    }
    return dp(pos,0,false,false,false);
}
signed main()
{
    memset(f,-1,sizeof(f));
    int t;
    scanf("%lld",&t);
    int ans=0;
    while(t--)
    {
        int l,r;
        scanf("%lld%lld",&l,&r);
        ans^=cul(r)-cul(l-1);
    }
    printf("%lld\n",ans);
}
全部评论

相关推荐

投递长鑫存储等公司7个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务