标签:回文串 code else print 运算 memset 大战 size ++i
一个很简单的DP.就是有一种情况他可能前面的都不管然后直接下药没考虑到.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define met(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=1e5+7;
ll dp[maxn][2];
const int inf=0x3f3f3f3f;
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
ll ans=-inf;ll s;
memset(dp,0,sizeof(dp));
for(int i=1; i<=n; ++i){
scanf("%lld",&s);
if(i==1){
dp[i][0]=s;
dp[i][1]=max(dp[i-1][0]+m,m);
}
else{
dp[i][0]=max(s,dp[i-1][0]+s);
dp[i][1]=max(max(dp[i-1][0]+m,dp[i-1][1]+s),m);
}
ans=max(ans,dp[i][1]);
}
printf("%lld\n",ans);
return 0;
}
一直想着怎么把数弄得很大,忘记取摸这个操作
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
ll qpow(ll a,ll n,ll mod){
ll res=1;
while(n){
if(n&1){
res*=a;
res%=mod;
}
n>>=1;
a=(a*a)%mod;
}
return res;
}
int main(){
int n;scanf("%d",&n);
while(n--) {
int t, r;
scanf("%d%d", &t, &r);
int ans=0,i;
for(i=0;i<=1000;++i){
ans=(ans+qpow(10,i,r)*t%r)%r;
if(ans==0) break;
}
if(i==1001){
puts("GG");
}
else printf("%d\n",i);
}
}
两种情况
一个是从奇数出发,一个是从偶数出发
当出现?直接相等就好
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define mp make_pair
#define met(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=1e5+7;
string s;
int n;
ll gao(){
ll ans = 0;
for (register int i=0; i<n;++i){
for (register int j=0; i+ j <n && i-j>=0 ; ++j){
if(s[i-j]==s[i+j]||s[i-j]=='?'||s[i+j]=='?')
ans++;
else break;
}
for (register int j=0; i + j <n && i-1-j>=0; ++j){
if(s[i-1-j]==s[i+j]||s[i-1-j]=='?'||s[i+j]=='?')
ans++;
else break;
}
}
return ans;
}
int main(){
cin>>n;cin>>s;
cout<<gao()<<endl;
return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define met(a,x) memset(a,x,sizeof(a))
using namespace std;
int s[101];
int d[101][101];
const int inf=0x3f3f3f3f;
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; ++i)
{
scanf("%d",&s[i]);
}
for(int i=2; i<=n; ++i)
{
scanf("%d",&d[i][i-1]);
d[i-1][i]=d[i][i-1];
}
int ans=inf,tmp;
for(int i=1; i<=n; ++i)
{
int t=0;
tmp=0;
if(i!=n){
for(int j=i; j<=n; ++j){
tmp+=s[j]+t;
t+=d[j][j+1];
}
int p=i-1;
t*=2;
t+=d[p][i];
for(int j=p; j>=1; --j){
tmp+=s[j]+t;
t+=d[j][j-1];
}
ans=min(ans,tmp);
//cout<<ans<<" "<<i<<endl;
}
if(i!=1){
t=0;
tmp=0;
for(int j=i; j>=1; --j){
tmp+=s[j]+t;
t+=d[j][j-1];
}
t*=2;
t+=d[i][i+1];
for(int j=i+1; j<=n; ++j){
tmp+=s[j]+t;
t+=d[j][j+1];
}
ans=min(ans,tmp);
//cout<<ans<<" "<<i<<endl;
}
}
printf("%d\n",ans);
return 0;
}
标签:回文串 code else print 运算 memset 大战 size ++i
原文地址:https://www.cnblogs.com/smallocean/p/10270973.html