zoukankan      html  css  js  c++  java
  • CodeForces 464 B Restore Cube

    Restore Cube

    题解:

    x->yyy

    其实就是把x代替成yyy这个值。

    如果不好理解的话, 可以试想一下, 刚开始的话 0->0, 1->1, 2->2,...,9->9.

    现在有一条指令 1->23

    那么就是就是0->0, 1->23, 2->2,...,9->9.

    现在又有一条指令2->45

    那么就相当于0->0, 1->453, 2->45,...,9->9.

    就相当于我们求出0~9每个数字分别代表的是什么东西。

    然后我们倒着DP给定的指令。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
    #define LL long long
    #define ULL unsigned LL
    #define fi first
    #define se second
    #define pb push_back
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define lch(x) tr[x].son[0]
    #define rch(x) tr[x].son[1]
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    typedef pair<int,int> pll;
    const int inf = 0x3f3f3f3f;
    const int _inf = 0xc0c0c0c0;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const LL _INF = 0xc0c0c0c0c0c0c0c0;
    const LL mod =  (int)1e9+7;
    const int N = 1e5 + 100;
    char s[N];
    string str[N];
    LL dp[15], base[15];
    void solve(string & sstr){
        int m = sstr[0] - '0';
        int len = sstr.size();
        LL tmp_base = 1; LL tmp_yu = 0;
        for(int i = 3; i < len; ++i){
            int id = sstr[i] - '0';
            tmp_base = (tmp_base * base[id]) % mod;
            tmp_yu = (tmp_yu * base[id] + dp[id]) % mod;
        }
        dp[m] = tmp_yu, base[m] = tmp_base;
    //    cout << m << ' ' << dp[m] << ' '  << base[m] << endl;
    }
    int main(){
        scanf("%s", s+1);
        int n;
        scanf("%d", &n);
        for(int i = 0; i < 10; ++i)
            dp[i] = i, base[i] = 10;
        for(int i = 1; i <= n; ++i){
            cin >> str[i];
        }
        for(int i = n; i >= 1; --i){
            solve(str[i]);
        }
        int m = strlen(s+1);
        LL ans = 0;
        for(int i = 1; i <= m; ++i){
            int id = s[i] - '0';
            ans = (ans * base[id] + dp[id]) % mod;
        }
        cout << ans << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    redis中的发布订阅(Pub/Sub)
    emmc基础技术8:操作模式3-interrupt mode
    Linux命令-tar
    git获取内核源码的方法
    Linux内核基础设施
    Linux内核简介
    emmc基础技术8:操作模式2-device identification mode
    内核子系统文档撰写方法
    eMMC基础技术6:eMMC data读写
    eMMC基础技术10:寄存器介绍
  • 原文地址:https://www.cnblogs.com/MingSD/p/10868083.html
Copyright © 2011-2022 走看看