MCPcopy Create free account
hub / github.com/LeadCoding/3-weeks-Google-Prep / help

Function help

02. Dynamic Programming/1. Barcode.cpp:4–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3#define int long long
4int help(int j,int last,int siz,vector<int>&v,int x,int y,int n,int dp[1001][1001][2]) {
5 if(j==v.size()&&siz<x) return INT_MAX;
6 if(j==v.size()) return 0;
7 if(siz>y) return INT_MAX;
8
9 if(dp[j][siz][last]!=-1)return dp[j][siz][last];
10 int black = v[j];
11 int white = n-v[j];
12 dp[j][siz][last] = INT_MAX;
13 if(siz==0) {
14 dp[j][siz][last]=min(white+help(j+1,1,1,v,x,y,n,dp),black+help(j+1,0,1,v,x,y,n,dp));
15 } else {
16
17 dp[j][siz][last] = min(dp[j][siz][last],(last==1?white:black)+help(j+1,last,siz+1,v,x,y,n,dp));
18
19 if(siz>=x)
20 {
21 dp[j][siz][last] = min(dp[j][siz][last],(last==1?black:white)+help(j+1,1-last,1,v,x,y,n,dp));
22 }
23
24 }
25
26 return dp[j][siz][last];
27
28
29
30}
31int32_t main() {
32 int n,m,x,y;
33

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected