Блог пользователя MARTIIROSYAN

Автор MARTIIROSYAN, история, 5 месяцев назад, По-русски

this day i wanna teach you how to solve this hardest problem in codeforces 282A - Bit++ , this is so interesting problem, we can use DP for fast solution, we can calc max and min answer using DP, and answer in problem is min+max

#include <bits//stdc++.h>
using namespace std;
int read_num(){
    int a;
    cin>>a;
    return a;
}
char read_char(){
    char a;
    cin>>a;
    return a;
}
string read_str(int len){
    string a;
    while(len--)a+=read_char();
    return a;
}
int find_score(string a){
    return count(begin(a),end(a),'+')?1:-1;
}
int main()
{
    int n=read_num();
    vector<string>a(n);
    vector<int>score(n);
    vector<vector<int>>dp1(n),dp2(n);
    for(int i=0;i<n;++i)a[i]=read_str(3),score[i]=find_score(a[i]);
    for(int i=0;i<n;++i)dp1[i]=vector<int>(i+2,/*infinity*/n*500),dp2[i]=vector<int>(i+2,/*-infinity*/-n*500);
    dp1[0][0]=0;
    dp1[0][1]=score[0];
    for(int i=1;i<n;++i){
        for(int j=0;j<=i;++j){
            dp1[i][j]=min(dp1[i][j],dp1[i-1][j]);
            dp1[i][j+1]=min(dp1[i][j+1],dp1[i-1][j]+score[i]);
        }
    }
    dp2[0][0]=0;
    dp2[0][1]=score[0];
    for(int i=1;i<n;++i){
        for(int j=0;j<=i;++j){
            dp2[i][j]=max(dp2[i][j],dp2[i-1][j]);
            dp2[i][j+1]=max(dp2[i][j+1],dp2[i-1][j]+score[i]);
        }
    }
    cout<<(*min_element(begin(dp1[n-1]),end(dp1[n-1])))+(*max_element(begin(dp2[n-1]),end(dp2[n-1])))<<'\n';
}

nice problem, after 10 likes i teach you how to solve 1A - Theatre Square

Полный текст и комментарии »

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

Автор MARTIIROSYAN, история, 5 месяцев назад, По-русски

hi everybody, this day i wanna teach how to solve 71A - Way Too Long Words with DP

include<bits//stdc++.h>

using namespace std; int check_size(string a){ //this function can calc lenght your string int c=0; vectors; for(auto&i:a)s.push_back(i),c++; assert(c>=s.size()); return max(c,(int)s.size()); } struct DP{ string a; void read(){ cin>>a; } int middle_number(int n){ // calc middle number vectordp(n); for(int i=0;i<n;++i){ dp[i]=(i and i+110); if(i>0)dp[i]+=dp[i-1]; } return dp[n-1]; } char get(int i,int n){ for(int j=0;j<n;j++)if(j==i) return a[j]; return '*'; } string ans(){ int n=check_size(a),nm=middle_number(n); string answer=get(0,n)+to_string(nm)+get(n-1,n); if(n<=10)answer=a; return answer; } }; int main() { int n; cin>>n; while(n--){ DP dp; dp.read(); cout<<dp.ans()<<'\n'; } } after 20 like i share solutions this problem 231A - Team

Полный текст и комментарии »

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

Автор MARTIIROSYAN, история, 5 месяцев назад, По-русски

this day i wanna teach everyone segment tree we can solve a problem 4A - Watermelon lets go you can build this segment tree for sum

include<bits//stdc++.h>

using namespace std; string solve(string a,int n){ if(a=="dzmeruk"){ //this code for problem watermelon if(n==88){return "i dont have any solve for this";} if(n==2 or n%2)return "NO\n"; else return "YES\n"; } } struct segment{ int n; void f(){ cin>>n; cout<<solve("dzmeruk",n); } }; int main(){

segment x; x.f(); } after 10 likes i can teach everyone how to solve this 71A - Way Too Long Words

Полный текст и комментарии »

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится