@Yeasion-Nein
2018-09-09T14:25:14.000000Z
字数 15390
阅读 1137
1.是从层爬上第层的
2.是用膜魔法飞上第层的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 10010
using namespace std;
int n,dp[MAXN];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&dp[i]);
for(int i=1;i<=n+1;i++)
dp[i]=min(dp[i-1],min(dp[i-2],dp[i-3]))+dp[i];
//对于所有的情况,直接取min就好了。
printf("%d",dp[n+1]);
return 0;
}
1、删除一个字符;
2、插入一个字符;
3、将一个字符改为另一个字符;
(!皆为小写字母!)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2010
using namespace std;
string a,b;
char s1[MAXN],s2[MAXN];
int f[MAXN][MAXN];
int DP(int i,int j){
if(f[i][j]!=-1) return f[i][j];
if(i==0) return f[i][j]=j;
if(j==0) return f[i][j]=i;
int ken=1;
if(s1[i]==s2[j]) ken=0;
return f[i][j]=min(min(DP(i-1,j)+1,DP(i,j-1)+1),DP(i-1,j-1)+ken);
}
int main(){
cin>>a>>b;
int len1=a.length();
int len2=b.length();
memset(f,-1,sizeof(f));
for(int i=1;i<=len1;i++)
s1[i]=a[i-1];
for(int i=1;i<=len2;i++)
s2[i]=b[i-1];
DP(len1,len2);
printf("%d",f[len1][len2]);
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1010
using namespace std;
int a[MAXN],dp[MAXN][MAXN][2];
int n,w;
int main(){
scanf("%d%d",&n,&w);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
a[i]--;
}
for(int i=1;i<=n;i++){
dp[i][0][0]=dp[i-1][0][0]+(a[i]^1);
for(int j=1;j<=w;j++){
dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-1][1])+(a[i]^1);
dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j-1][0])+a[i];
}
} int ans=0;
for(int i=1;i<=w;i++)
ans=max(ans,max(dp[n][i][1],dp[n][i][0]));
printf("%d",ans); return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1010
#define INF 0x7fffffff
using namespace std;
int n,m,c,f[MAXN][MAXN];
int a[MAXN][MAXN];
int main(){
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
//输入
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
f[i][j]=a[i][j]+f[i-1][j]+f[i][j-1]-f[i-1][j-1];
//求二维前缀和
int ans=-INF,mi,mj;
for(int i=1;i<=n-c+1;i++)
for(int j=1;j<=m-c+1;j++){
int x=i+c-1; int y=j+c-1;
if(ans<f[x][y]-f[i-1][y]-f[x][j-1]+f[i-1][j-1]){
ans=f[x][y]-f[i-1][y]-f[x][j-1]+f[i-1][j-1];
//取max操作
mi=i; mj=j;
}
}
printf("%d %d",mi,mj);
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1010
#define INF 0x7fffffff
#define ll long long
using namespace std;
ll n,dp[MAXN][MAXN];
int main(){
scanf("%lld",&n);
dp[0][0]=1;
for(int i=1;i<=2*n;i++){
for(int j=0;j<=n&&j<=i;j++){
if(j>=1) dp[i][j]+=dp[i-1][j-1];
if(j<=i) dp[i][j]+=dp[i-1][j+1];
}
}
printf("%lld",dp[2*n][0]);
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 110
using namespace std;
int n,m,f[MAXN][MAXN];
bool map[MAXN][MAXN];
int ans=0;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
scanf("%d",&map[i][j]);
if(map[i][j]==1)
f[i][j]=min(min(f[i-1][j],f[i][j-1]),f[i-1][j-1])+1;
ans=max(f[i][j],ans);
}
printf("%d",ans);
return 0;
}
输出格式:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2010
using namespace std;
int dp[MAXN][MAXN];
int a[MAXN],n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=0;j<=i;j++){
int l=i-j;
dp[i][j]=max(dp[i-1][j]+a[n-l+1]*i,dp[i-1][j-1]+a[j]*i);
} int ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[n][i]);
printf("%d",ans); return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 10010
using namespace std;
int dp[MAXN][MAXN];
int n,a[MAXN];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
dp[i][i]=a[i];
}
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
dp[i][j]=abs((a[j]-a[i])*(j-i+1));
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
for(int k=i;k<j;k++){
dp[i][j]=max(dp[i][k]+dp[k+1][j],dp[i][j]);
}
printf("%d",dp[1][n]); return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 10010
#define ll long long
using namespace std;
ll a[MAXN],dp[MAXN];
ll sum[MAXN],n,t;
int main(){
scanf("%lld%lld",&n,&t);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
//前缀和
}
for(int i=1;i<=n;i++){
dp[i]=dp[i-1]+a[i]*n*n;
for(int j=1;j<=i-1;j++){
ll k=a[j]+a[i];
if(k<=t)
dp[i]=min(dp[i],dp[j-1]+k*(sum[i]-sum[j-1]));
}
}
printf("%lld",dp[n]); return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 10010
#define ll long long
using namespace std;
ll n,a[MAXN],dp[MAXN];
ll sum[MAXN];
int main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
if(sum[i]>=0) dp[i]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
if(sum[i]-sum[j]>=0&&dp[j])
dp[i]=max(dp[j]+1,dp[i]);
if(dp[n]) printf("%lld",dp[n]);
else puts("Impossible");
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 50
using namespace std;
int n,m,dp[MAXN][MAXN];
int main(){
scanf("%d%d",&n,&m);
dp[1][0]=1;
for(int k=1;k<=m;k++){
dp[1][k]=dp[2][k-1]+dp[n][k-1];
for(int i=2;i<n;i++)
dp[i][k]=dp[i-1][k-1]+dp[i+1][k-1];
dp[n][k]=dp[n-1][k-1]+dp[1][k-1];
}
printf("%d",dp[1][m]); return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 500
#define rqy 1000007
using namespace std;
int n,m,a[MAXN];
int dp[MAXN][MAXN];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=0;i<=n;i++)
dp[i][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=a[i];j++){
for(int k=0;k<=m-j;k++){
if(j==0&&k==0) continue;
dp[i][j+k]+=dp[i-1][k];
dp[i][j+k]%=rqy;
}
}
}
printf("%d",dp[n][m]%rqy);
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 350
#define MAXM 120
#define Inf 0x7fffffff
#define LL long long
using namespace std ;
int N, M, Value[MAXN], Card[5] ;
int Dp[MAXM][MAXM][MAXM][MAXM] ;
int Max_Num ;
int Read(){
int X = 0 ; char ch = getchar() ;
while(ch > '9' || ch < '0') ch = getchar() ;
while(ch <= '9' && ch >= '0')
X = (X << 1) + (X << 3) + (ch ^ 48), ch = getchar() ;
return X ;
}
int main(){
N = Read() ; M = Read() ;
for(int i = 1; i <= N; i ++){
Value[i] = Read() ;
}
Dp[0][0][0][0] = Value[1] ;
for(int i = 1; i <= M; i ++){
int X ; X = Read() ;
Card[X] ++ ;
}
for(int A = 0; A <= Card[1]; A ++)
for(int B = 0; B <= Card[2]; B ++)
for(int C = 0; C <= Card[3]; C ++)
for(int D = 0; D <= Card[4]; D ++){
int R = A + B * 2 + C * 3 + D * 4 + 1 ;
if(A != 0) Dp[A][B][C][D] = max(Dp[A][B][C][D], Dp[A - 1][B][C][D] + Value[R]) ;
if(B != 0) Dp[A][B][C][D] = max(Dp[A][B][C][D], Dp[A][B - 1][C][D] + Value[R]) ;
if(C != 0) Dp[A][B][C][D] = max(Dp[A][B][C][D], Dp[A][B][C - 1][D] + Value[R]) ;
if(D != 0) Dp[A][B][C][D] = max(Dp[A][B][C][D], Dp[A][B][C][D - 1] + Value[R]) ;
}
printf("%d", Dp[Card[1]][Card[2]][Card[3]][Card[4]]) ;
return 0 ;
}
那么暂时到此为止(个题还没刷完啊啊啊啊啊)