头像

Keven11




离线:7天前


最近来访(30)
用户头像
直行格子
用户头像
丶Kingdom
用户头像
253718226
用户头像
PDX
用户头像
nuo0930
用户头像
zombotany
用户头像
蜗牛往上爬
用户头像
青门
用户头像
星夜之下
用户头像
篮网
用户头像
D.devil
用户头像
shine_nhy
用户头像
HEARTheart
用户头像
无名氏DU
用户头像
書盡


Keven11
1个月前
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
int dp[55][55];
int main() {
    string s;
    cin >> s;
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 0; i < s.size(); i++) {
        dp[i][i] = 1;
    }
    for (int l = 2; l <= s.size(); l++) {
        for (int i = 0; i < s.size() - l + 1; i++) {
            int j = i + l - 1;
            if (s[i] == s[j]) {
                if (l == 2) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = min(min(dp[i + 1][j], dp[i][j - 1]), dp[i + 1][j - 1] + 1);
                }
            }  else {
                for (int k = i; k < j; k++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
                }
            }
        }
    }
    cout<<dp[0][s.size()-1]<<endl;
    return 0;
}


活动打卡代码 AcWing 125. 耍杂技的牛

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
typedef long long ll;
const int N = 5e4+5;
struct node{
int w,s;
}a[N];
int n;
bool cmp(node a,node b){
return a.w+a.s<=b.w+b.s;
}
ll sum=0;
int ans=0;
int main(){
cin>>n;
for(int i=1;i<=n;i) cin>>a[i].w>>a[i].s;
sort(a+1,a+n+1,cmp);
ans=sum-a[1].s;
sum=a[1].w;
for(int i=2;i<=n;i
){
if(sum-a[i].s>ans) ans=sum-a[i].s;
sum+=a[i].w;
}
cout<<ans<<endl;
return 0;
}



活动打卡代码 AcWing 104. 货仓选址

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for (int i=(a);i<(b);i++)

using namespace std;
const int N=1e5+5;
int a[N];
void c_plus(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int main(){
c_plus();
int n;
cin>>n;
_for(i,0,n){
cin>>a[i];
}
sort(a,a+n);
int m=n-(n&1)>>1;
int ans=0;
_for(i,0,n){
ans+=abs(a[i]-a[m]);
}
cout<<ans<<endl;
return 0;
}



活动打卡代码 AcWing 913. 排队打水

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for (int i=a;i<b;i++)

using namespace std;
typedef long long LL;
int a[100005];
int main(){
int n;
LL ans=0;
scanf(“%d”,&n);
_for(i,0,n){
scanf(“%d”,&a[i]);
}
sort(a,a+n);
_for(i,0,n){
ans+=(LL)a[i]*(n-i-1);
}
printf(“%lld”,ans);
return 0;
}



活动打卡代码 AcWing 148. 合并果子

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
int main(){
int n;
priority_queue[HTML_REMOVED],greater[HTML_REMOVED] > pq;
scanf(“%d”,&n);
for (int i=0;i<n;i++){
int x;
scanf(“%d”,&x);
pq.push(x);
}
int ans=0,t;
while (–n){
t=0;
t+=pq.top();
pq.pop();
t+=pq.top();
pq.pop();
ans+=t;
pq.push(t);
}
printf(“%d”,ans);
return 0;
}



活动打卡代码 AcWing 907. 区间覆盖

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

using namespace std;
const int N=1e5+5;
struct Range{
int l,r;
bool operator<(const Range &w) const{
return l[HTML_REMOVED]=ed){
flag=true;
break;
}
st=r;
i=j-1;
}
if (!flag){
ans=-1;
}
printf(“%d\n”,ans);
return 0;
}



活动打卡代码 AcWing 906. 区间分组

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for (int i=(a);i<(b);i++)

using namespace std;
void c_plus(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int N=1e5+5;
struct Range{
int l,r;
bool operator<(const Range &w) const{
return l[HTML_REMOVED]>n;
_for(i,0,n){
int l,r;
cin>>l>>r;
range[i]={l,r};
}
sort(range,range+n);
priority_queue[HTML_REMOVED],greater[HTML_REMOVED] > heap;
_for(i,0,n){
Range now=range[i];
if (heap.empty() || heap.top()>=now.l){
heap.push(now.r);
}else{
heap.pop();
heap.push(now.r);
}
}
cout<<heap.size()<<endl;
return 0;
}




Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for(int i=(a);i<(b);i++)

using namespace std;
const int N=1e5+5;
int n;
struct Range{
int l,r;
bool operator<(const Range &w) const{
return r[HTML_REMOVED]>n;
_for(i,0,n){
int l,r;
cin>>l>>r;
range[i]={l,r};
}
sort(range,range+n);
int ans=0,ed=-0x7fffffff;
_for(i,0,n){
if (range[i].l>ed){
ans++;
ed=range[i].r;
}
}
cout<<ans<<endl;
return 0;
}



活动打卡代码 AcWing 905. 区间选点

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for(int i=(a);i<(b);i++)

using namespace std;
const int N=1e5+5;
int n;
struct Range{
int l,r;
bool operator<(const Range &w) const{
return r[HTML_REMOVED]>n;
_for(i,0,n){
int l,r;
cin>>l>>r;
range[i]={l,r};
}
sort(range,range+n);
int ans=0,ed=-0x7fffffff;
_for(i,0,n){
if (range[i].l>ed){
ans++;
ed=range[i].r;
}
}
cout<<ans<<endl;
return 0;
}



活动打卡代码 AcWing 901. 滑雪

Keven11
2个月前

include[HTML_REMOVED]

include[HTML_REMOVED]

define _for(i,a,b) for (int i=(a);i<(b);i++)

using namespace std;
const int N=3e2+5;
int r,c,a[N][N],dp[N][N],ans,d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
bool in(int x,int y){
return x>=0 && x[HTML_REMOVED]=0 && y[HTML_REMOVED]>r>>c;
_for(i,0,r){
_for(j,0,c){
cin>>a[i][j];
}
}
_for(i,0,r){
_for(j,0,c){
ans=max(dfs(i,j)+1,ans);
}
}
cout<<ans<<endl;
return 0;
}