Skip to content

Instantly share code, notes, and snippets.

@bunnykek
Created October 18, 2023 07:55
Show Gist options
  • Save bunnykek/e76bc90624223ffe1015c0eb08159be1 to your computer and use it in GitHub Desktop.
Save bunnykek/e76bc90624223ffe1015c0eb08159be1 to your computer and use it in GitHub Desktop.
One box
// You are working in the resource distribution team of your company A One block is a block of data having exactly one resource which has vatus 1 You are given an array
// A containing N resource values What is the number of ways to divide the array into continuous blocks such that each block
```
int main() {
vector<int> v = {0 ,1, 0};
int n = v.size();
vector<int> dp(n+1, 1);
for(int i=n-1; i>=0; i--){
int count = 0, sum = 0;
for(int k=i; sum<=1 and k<v.size(); k++){
sum+=v[k];
if(sum==1) count += dp[k+1];
}
dp[i]=count;
}
cout<< dp[0];
}
```
@Ash4dev
Copy link

Ash4dev commented Oct 29, 2024

`#include <bits/stdc++.h>
using namespace std;

int main()
{
int n; cin>>n;
vector v(n);
int ans=1;
for(int i=0; i<n; i++){
cin>>v[i];
}
int cnt=1;
bool f = 0;
for(int i=0; i<n; i++){
if(v[i]) f=1;
if(f){
if(!v[i]) cnt++;
else{
ans*= cnt;
cnt = 1;
}
}
}
cout<<ans;
return 0;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment