摘要:
首先我们知道一维的时候,可以达到Q(N)的速度,那二维的时候,我们依然可以通过降维来引用1维的做法#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>using namespace std;int map[102][102];int main(){ int i,j,t,k,m,r,c,max,temp; scanf("%d",&t); while( 阅读全文
摘要:
这是个二维的矩阵,从原点到下一个点只有两个方向,从上到下、从左到右遍历不会产生冲突#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>using namespace std;int dp[30][30];//当前的位置最大和是多少int main(){ int n,m,i,j; while(~scanf("%d%d",&n,&m)) { m 阅读全文
摘要:
很简单的01背包:#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>using namespace std;int dp[30005];int main(){ int t,v,n,i,j,val,level; scanf("%d",&t); while(t--) { scanf("%d%d",&v,&n); m 阅读全文
摘要:
经典的数塔问题:#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>using namespace std;int dp[105][105];int main(){ int n,i,j; while(~scanf("%d",&n)) { memset(dp,0,sizeof(dp)); for(i=1;i<=n;++i) for(j=1;j& 阅读全文
摘要:
首先,我们把字符串反转,然后用反串和原串求最大公共子序列,再用字符串长度减去最大公共子序列的长度就是答案,我们还可以用滚动数组优化内存状态转移方程:(i长度的a串和j长度的b串的最长公共子序列长度) 1.dp[i-1][j-1]+1 a[i]=b[j]dp[i][j]= 2.max(dp[i][j-1],dp[i-1][j]) a[i]!=b[j]#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include&l 阅读全文