AtCoder-abc189_d Logical Expression

A
Problem NameLogical Expression
JudgeAtCoder
Problem Linkhttps://atcoder.jp/contests/abc189/tasks/abc189_d
Algorithms & DSDynamic Programming
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define sf(n) scanf("%lld",&n); #define YES printf("YES\n"); #define NO printf("NO\n"); #define nl printf("\n"); #define PB push_back #define VST(V) sort(V.begin(),V.end()) #define VSTrev(V) sort(V.begin(),V.end(),greater<long long int>()) #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); vector<ll>V; ll mem[70][3],n; ll dp(ll i,ll bit) { if(i>=n) { return bit; } if(mem[i][bit]!=-1) { return mem[i][bit]; } ll ans=0; if(V[i]==0) { ans+=dp(i+1,bit|0); ans+=dp(i+1,bit|1); } else { ans+=dp(i+1,bit&0); ans+=dp(i+1,bit&1); } return mem[i][bit]=ans; } int main() { //freopen("1input.txt","r",stdin); fast; ll tcase=1; //cin>>tcase; for(ll test=1; test<=tcase; test++) { cin>>n; for(ll i=0; i<n; i++) { string s; cin>>s; if(s=="OR") V.PB(0); else { V.PB(1); } } for(ll i=0; i<=n; i++) { mem[i][0]=mem[i][1]=-1; } ll ans=dp(0,0); ans+=dp(0,1); cout<<ans<<"\n"; } return 0; }
Code language: PHP (php)

About the author

Sheikh Arman Hossain
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

আবু রিফাত মুহাম্মদ

সখের বশে প্রোগ্রামিং করি। নতুন নতুন জিনিস শিখতে এবং শেখাতে ভালবাসি।

যোগাযোগ করুন

error: Alert: Content is protected !!