-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeb173_1.cpp
More file actions
66 lines (64 loc) · 1.16 KB
/
feb173_1.cpp
File metadata and controls
66 lines (64 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits.h>
#include<bits/stdc++.h>
using namespace std;
bool check(int u,int v,vector<int>& seq,int ind,int n)
{
if(u>v)
return false;
else if(u<0 || v<0 ||u>=n || v>=n)
return false;
else if(v-u+1>seq[ind])
return false;
return true;
}
int dp(int u,int v,vector<int>& arr,vector<int>& seq,vector<int> & sum,int** mat,int ind)
{
if(ind>seq.size())
return 0;
int length=seq[ind];
int n=arr.size();
int maxm=INT_MIN;
for(int i=u;i<=v-length+1;i++)
{
if(check(i+1,i+length-2,seq,ind+1,n)){
int tt;
if(mat[i+1][i+length-2]!=-1)
tt=mat[i+1][i+length-2];
else
tt=dp(i+1,i+length-2,arr,seq,sum,mat,ind+1);
int temp=sum[i+length]-sum[i]-tt;
if(temp>maxm)
maxm=temp;
}
}
cout<<"sdasddasf";
mat[u][v]=maxm;
return maxm;
}
main()
{
int test;
cin>>test;
int n;int m;
cin>>n>>m;
vector<int> arr(n);
vector<int> sum(n+1);
int temp=0;
sum[0]=0;
for(int i=0;i<n;i++)
{cin>>arr[i];
temp+=arr[i];
sum[i+1]=temp;
}
vector<int> seq(m);
for(int i=0;i<m;i++)
cin>>seq[i];
int** mat=(int**)malloc(sizeof(int*)*n);
for(int i=0;i<n;i++)
mat[i]= (int*)malloc(sizeof(int)*n);
memset(mat,-1,sizeof(mat));
cout<<dp(0,seq[0],arr,seq,sum,mat,0);
}