简单的dp 但是一个大数加法  套用了末位大牛的类模板

#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxs 10005
#define maxn 110
using namespace std;
char X[maxs], Z[maxn];
struct bign
{
int len, s[maxn];
bign operator = (const char *num)
{
len = strlen(num);
for (int i = 0; i < len; i++)
s[i] = num[len-i-1]-'0';
return *this;
}
bign operator + (const bign &b) const
{
bign c; c.len = 0;
for (int i = 0, g = 0; g || i < max(len, b.len); i++)
{
int x = g;
if (i < len) x += s[i];
if (i < b.len) x += b.s[i];
c.s[c.len++] = x%10;
g = x/10;
}
return c;
}
bign operator += (const bign &b)
{
*this = *this + b;
return *this;
}
void print()
{
for (int i = len-1; i >= 0; i--)
printf("%d", s[i]);
}
};
bign dp[maxn][maxs];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s%s", X+1, Z+1);
int len1 = strlen(X+1), len2 = strlen(Z+1);
for (int i = 0; i <= len1; i++)
dp[0][i] = "1";
for (int i = 1; i <= len2; i++)
for (int j = i; j <= len1; j++)
{
dp[i][j] = dp[i][j-1];
if (Z[i] == X[j])
dp[i][j] += dp[i-1][j-1];
}
dp[len2][len1].print();
//printf("%d",dp[len2][len1]);
puts("");
}
return 0;
}

uva 10069的更多相关文章

  1. uva 10069 Distinct Subsequences 【dp+大数】

    题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...

  2. uva 10069 Distinct Subsequences(高精度 + DP求解子串个数)

    题目连接:10069 - Distinct Subsequences 题目大意:给出两个字符串x (lenth < 10000), z (lenth < 100), 求在x中有多少个z. ...

  3. UVA 10069 Distinct Subsequences(DP)

    考虑两个字符串,我们用dp[i][j]表示字串第到i个和字符串到第j个的总数,由于字串必须连续 因此dp[i][j]能够有dp[i][j-1]和dp[i-1][j-1]递推而来,而不能由dp[i-1] ...

  4. UVa 10069 Distinct Subsequences(大数 DP)

     题意 求母串中子串出现的次数(长度不超过1后面100个0  显然要用大数了) 令a为子串 b为母串 d[i][j]表示子串前i个字母在母串前j个字母中出现的次数   当a[i]==b[j]&am ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. 关于java的static关键字

    通常来说,当你创建类时,就是在描述那个类的对象的外观与行为.除非你用new创建那个类的对象,否则,你实际上并未获得任何东西.当你用new来创建对象时,数据存储空间才被分配,其方法才供外界调用. 但是有 ...

  2. JavaScript之可运行按钮

    看到好多大神都写了像这种在页面"可运行"的Javascript脚本,感觉很好奇,所以我今天也试着写了一个. 自从有了这个"可运行"按钮,好多代码就再也不以图片的 ...

  3. Apache httpd开启SSL

    https://my.oschina.net/xpbug/blog/197454 必要软件 apache httpd 2.4(windows) perl 5 (windows) openssl (wi ...

  4. iOS - 数组与字典(NSArray & NSDictionary)

    1. 数组的常用处理方式 //--------------------不可变数组 //1.数组的创建 NSString *s1 = @"zhangsan"; NSString *s ...

  5. 用sublime编译C++的方法

    sublime代码高亮这么好看,怎么能不用sublime敲代码呢: ) 本人用的版本是sublime Text3中文版 在网上查了查,自己的sublime现在也能编译C++了,设置步骤如下: 1.找到 ...

  6. .Net Core 项目中的包引用探索(使用VSCode)

    本文组织有点乱,先说结论吧: 1 在 project.json 文件中声明包引用. 而不是像以前那样可以直接引用 dll. 2 使用 dotnet restore 命令后,nuget 会把声明的依赖项 ...

  7. stl::search

    template<class ForwardIt1, class ForwardIt2> ForwardIt1 search(ForwardIt1 first, ForwardIt1 la ...

  8. Jquery实现搜索框提示功能

    博客的前某一篇文章中http://www.cnblogs.com/hEnius/p/2013-07-01.html写过一个用Ajax来实现一个文本框输入的提示功能.最近在一个管理项目的项目中,使用后发 ...

  9. aix用命令查监听端口对应的进程

    --aix$netstat -an|grep LISTEN|grep 7867tcp4 0 0 *.7867 *.* LISTEN$netstat -Aan|grep 7867f1000e00029f ...

  10. json数据与字符串相互转化的例子

    json与字符串之间的转换,本文分享一个小例子.   json转成string[需要引用json2.js文件]:  var arr=[{id:'id',name:'Spring'},{id:'id2' ...