博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa Distinct Subsequences
阅读量:4287 次
发布时间:2019-05-27

本文共 1373 字,大约阅读时间需要 4 分钟。

#include
#include
#include
#include
using namespace std;const int MAX = 120;char dp[MAX][MAX*1000][MAX];char str1[MAX*1000],str2[MAX];int aa[MAX],bb[MAX],cc[MAX];void Add(char *c,char *a,char *b){ int len1 = strlen(a); int len2 = strlen(b); memset(aa,0,sizeof(aa)); memset(bb,0,sizeof(bb)); memset(cc,0,sizeof(cc)); int len = max(len1,len2) + 3; for(int i = 0;i < len1;i++) aa[i] = a[len1-i-1]-'0'; for(int i = 0;i < len2;i++) bb[i] = b[len2-i-1]-'0'; int ct = 0; for(int i = 0;i < len;i++) { int s = aa[i] + bb[i] + ct; cc[i] = s%10; ct = s / 10; } int j; for(j = len;j>=0;j--) if(cc[j]) break; if(j < 0) c[0] = '0'; else for(int i = j;i>=0;i--) c[j-i] = cc[i] + '0'; c[j+1] = '\0';}int main(){ int n; scanf("%d",&n); while(n--) { scanf("%s%s",str1,str2); int len1 = strlen(str1); int len2 = strlen(str2); for(int i = 0; i <= len1; i++) strcpy(dp[0][i],"1"); for(int i = 1; i <= len2; i++) { strcpy(dp[i][0],"0"); for(int j = i; j<=len1; j++) { if(str2[i-1]==str1[j-1]) Add(dp[i][j],dp[i][j-1],dp[i-1][j-1]); else strcpy(dp[i][j],dp[i][j-1]); } } cout<
<

转载地址:http://qbsgi.baihongyu.com/

你可能感兴趣的文章
Ionic Tab选项卡使用整理(三)
查看>>
AngularJs控制器说明(一)
查看>>
Teleport Ultra网站静态资源下载工具
查看>>
AngularJs $http 请求服务整理
查看>>
ionic 加载动作$ionicLoading 和加载动画 ion-spinner
查看>>
使用Git获取最新版本到本地
查看>>
Visual Studio 调试器“启用编辑并继续”
查看>>
Cordova页面解析页面中script标签内容失败,Refused to execute inline script because it violates the following
查看>>
Ionic 中使用iframe嵌入外网页面整理
查看>>
Cordova config.xml配置WebView全屏浏览
查看>>
VS Code插件安装位置
查看>>
Cordova Ajax请求跨域问题整理
查看>>
Ionic ion-nav-view使用整理
查看>>
angularjs unsafe ng-href using javascript: void(0);
查看>>
AngularJs ng-bind-html指令整理
查看>>
cordova-plugin-whitelist 协议白名单配置整理
查看>>
cordova-plugin-network-information 网络状态获取整理
查看>>
cordova-plugin-device 获取设备信息整理
查看>>
cordova-plugin-vibration 设备震动整理
查看>>
Cordova事件整理
查看>>