日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 1080】Human Gene Functions(dp,可编辑距离类问题)

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 1080】Human Gene Functions(dp,可编辑距离类问题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

給你兩個DNA序列(長度不一定相同),你可以在其中任意位置上加入空格,使得最終他倆長度相同,最終相同長度的兩個DNA序列會有個相似度比較(每個字符相對應的比較),問你如何放置這些空格使得總相似度最大。

題目告訴你了空格和空格比較的權值是0,這樣就保證了答案的有窮性。不然如果是正數的話就可以無窮大了(本也不符合常識)

解題報告:

? 類似編輯距離xjb搞就行了。dp[i][j]代表第一個序列前i個和第二個序列前j個完全匹配的最優解。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 400 + 5; const int INF = 0x3f3f3f3f; int sc[MAX][MAX]; int dp[MAX][MAX]; char s1[MAX],s2[MAX]; int Max(int a,int b,int c) {return max(a,max(b,c)); } int main() {sc['A']['A']=5;sc['C']['C']=5;sc['G']['G']=5;sc['T']['T']=5;sc['A']['C']=sc['C']['A']=-1;sc['A']['G']=sc['G']['A']=-2;sc['A']['T']=sc['T']['A']=-1;sc['C']['G']=sc['G']['C']=-3;sc['A'][' ']=sc[' ']['A']=-3;sc['C']['T']=sc['T']['C']=-2;sc['C'][' ']=sc[' ']['C']=-4;sc['G']['T']=sc['T']['G']=-2;sc['G'][' ']=sc[' ']['G']=-2;sc['T'][' ']=sc[' ']['T']=-1;int t;cin>>t;while(t--) {int len1,len2;scanf("%d%s%d%s",&len1,s1+1,&len2,s2+1);for(int i = 0; i<=len1; i++) for(int j = 0; j<=len2; j++) dp[i][j] = -INF; dp[0][0]=0;for(int i = 1; i<=len1; i++) dp[i][0] = dp[i-1][0] + sc[s1[i]][' '];for(int i = 1; i<=len2; i++) dp[0][i] = dp[0][i-1] + sc[s2[i]][' ']; for(int i = 1; i<=len1; i++) {for(int j = 1; j<=len2; j++) {dp[i][j] = Max(dp[i-1][j-1]+sc[s1[i]][s2[j]],dp[i-1][j]+sc[s1[i]][' '],dp[i][j-1]+sc[s2[j]][' ']);}} printf("%d\n",dp[len1][len2]);}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【HDU - 1080】Human Gene Functions(dp,可编辑距离类问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。