【DP】 codeforces 464C Substitutes in Number
来源:互联网 发布:c语言中的异或运算符 编辑:程序博客网 时间:2024/05/03 16:59
倒过来DP即可。。。
#include <iostream> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits> #include <cstdlib>#include <cmath>#include <time.h>#define maxn 100005#define maxm 400005#define eps 1e-10#define mod 1000000007#define INF 999999999#define lowbit(x) (x&(-x))#define mp mark_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R //typedef vector<int>::iterator IT;typedef long long LL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}LL gcd(LL _a, LL _b){if(!_b) return _a;else return gcd(_b, _a%_b);}// headLL delta[20], shift[20];string s, q[maxn];int main(void){int n;cin >> s;scanf("%d", &n);for(int i = 0; i <= 10; i++) delta[i] = i, shift[i] = 10;for(int i = 1; i <= n; i++) cin >> q[i];for(int i = n; i >= 1; i--) {int len = q[i].size();LL t = 0, tt = 1;for(int j = len-1; j >= 3; j--) {t = (t + delta[q[i][j] - '0'] * tt) % mod;tt = shift[q[i][j] - '0'] * tt % mod;}int x = q[i][0] - '0';delta[x] = t;shift[x] = tt;}int len = s.size();LL ans = 0;for(int i = 0; i < len; i++) ans = (ans * shift[s[i] - '0'] + delta[s[i] - '0']) % mod;printf("%I64d\n", ans);return 0;}
0 0
- 【DP】 codeforces 464C Substitutes in Number
- codeforces 464C Substitutes in Number dp
- codeforces 464C Substitutes in Number
- Codeforces 464C Substitutes in Number
- Codeforces 464 C. Substitutes in Number
- codeforces #464C Substitutes in Number
- Codeforces 464C Substitutes in Number 同余定理+模拟
- Codeforces 464C Substitutes in Number(高效+快速幂)
- Codeforces 464 C. Substitutes in Number 动态规划法题解
- Codeforces Round #265 (Div. 2)E. Substitutes in Number(数学)
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
- codeforces 251C C. Number Transformation(数论+dp)
- Codeforces 480C Riding in a Lift dp
- codeforces #274C Riding in a Lift (dp)
- random number in C
- Missing number in C
- CodeForces 467C DP
- Codeforces 156C (DP)
- 刚开始学32,总结
- linux常用查看硬件设备信息命令
- Windows 下 Sublime text 2 运行程序出现[Error 2] 的解决办法
- java连接数据库(jdbc)
- 快速排序 小讲 - (二)【 理解 + 例题 】 更新 ing...
- 【DP】 codeforces 464C Substitutes in Number
- PHP微信公众开发笔记(三)
- [读Agile Software Development01]-Rules Behind Agile
- poj1248深度搜索简单题
- Java 异常类层次结构
- .NET通用JSON解析/构建类的实现(c#)
- Android环境搭建
- poj-1152
- 构建高并发高可用的电商平台架构实践