给定一个字符串s和m查询.对于每个查询,删除K第 - 次出现的字符x.
例如:
abcdbcaab
5
2 a
1 c
1 d
3 b
2 a
Ans abbc
Run Code Online (Sandbox Code Playgroud)
我正在使用BIT树进行更新操作.
码:
for (int i = 0; i < ss.length(); i++) {
char cc = ss.charAt(i);
freq[cc-97] += 1;
if (max < freq[cc-97]) max = freq[cc-97];
dp[cc-97][freq[cc-97]] = i; // Counting the Frequency
}
BIT = new int[27][ss.length()+1];
int[] ans = new int[ss.length()];
int q = in.nextInt();
for (int i = 0; …Run Code Online (Sandbox Code Playgroud) 我正在学习TSP并发现了TSP的这种递归解决方案
int compute(int start,int set)
{ int masked,mask,result=INT_MAX,temp,i;//result stores the minimum
if(g[start][set]!=-1)//memoization DP top-down,check for repeated subproblem
return g[start][set];
for(i=0;i<n;i++)
{ //npow-1 because we always exclude "home" vertex from our set
mask=(npow-1)-(1<<i);//remove ith vertex from this set
masked=set&mask;
if(masked!=set)//in case same set is generated(because ith vertex was not present in the set hence we get the same set on removal) eg 12&13=12
{
temp=adj[start][i]+compute(i,masked);//compute the removed set
if(temp<result)
result=temp,p[start][set]=i;//removing ith vertex gave us minimum
}
}
return g[start][set]=result;//return minimum
} …Run Code Online (Sandbox Code Playgroud)