Codeforces 56D Changing a String (DP) 题意:你可以对字符串s进行3种操作: 1,在pos位置插入字符ch。 2,删除pos位置的字符。 3,替换pos位置的字符为ch。 问最少需要多少次操作可以把字符s变成字符s1? 思路: 设dp[i][j]为字符串s的前i个字符替换成s1的前j个字符的最小花费。则有三种转移: 1:dp[i ...
}else{ dfs(n-1,m-1);if(a[n]!=b[m]) printf("REPLACE %d %c\n",m,b[m]); } }intmain(){ scanf("%s",a+1);n=strlen(a+1); scanf("%s",b+1);m=strlen(b+1);for(inti=0;i<=n;i++)for(intj=0;j<=m;j++) f[i][j]=0; f[0][0]=0;for(inti=1;i<=n;i++) ...
void dfs(int a, int b){ if(a == 0 && b==0)return ; if(s[a] == t[b] && dp[a-1][b-1] == dp[a][b]) dfs(a-1, b-1); else { if(a && dp[a-1][b] +1 == dp[a][b]) { P = node(1, a); P.put(); dfs(a-1, b); } else if(b && dp[a][b-1] ...
DELETEpos— delete a character numberpos(1 ≤ pos ≤ |s|) from the strings. At that the letters shift together and the length of the string decreases by 1. REPLACEposch— the letter in the positionposof the linesis replaced bych(1 ≤ pos ≤ |s|, A ≤ ch...
importjava.util.HashMap;importjava.util.Scanner;publicclassB501{publicstaticvoidmain(String[]args){Scanner sc=newScanner(System.in);int t=sc.nextInt();HashMap<String,String>map=newHashMap<>();while(t-->0){String a=sc.next();String b=sc.next();if(map.containsKey(a)){map.put(b,map...
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. ...
Linux from scratch Machine Learning Deep Learning CodeForces OpenCV TensonFlow Keras Spring CodinGame, Halit AI projects Kaggle and DevPost ML projects Learn GDB, Valgrind Cool Stuffs int a[100] = {0}; // shorter way to initialize in cpp. yeah, I didn't know that next_permutation(v.beg...
Codeforces 56D Changing a String 2016-07-13 18:39 −... GFY 0 218 @codeforces - 715E@ Complete the Permutations 2019-12-11 09:54 −[toc] --- ## @description@ 给定两个排列 p, q,他们中的有些位置被替换成了 0。 两个排列 p, q 的距离为:最少需要在 p 中执行交换两个元素的操作...
#include<string.h> using namespace std; #define ll int #define N 1010 char s[N], t[N]; int dp[N][N], n, m; // 0为插入 1为删除 2 3为替换 struct node{ int op; int pos; char c; node(int A=0,int E=0,char D=0):op(A),pos(E), c(D){} ...
关于map函数的一些巧妙运动 1 #include<iostream> 2 #include<map> 3 using namespace std; 4 int main(){ 5 string a,b; 6 map<string,string> ma; 7 in