이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int64_t n,k,a[100005],F[205][205][205];
bool Free[205][205][205];
vector<int> rs;
int64_t f(int64_t l,int64_t r,int64_t k)
{
if(Free[l][r][k]==true)
return F[l][r][k];
Free[l][r][k]=true;
if(k==0)
return F[l][r][k]=0;
F[l][r][k]=0;
int64_t pos;
for(int64_t i=l;i<r;i++)
for(int64_t kk=0;kk<k;kk++)
{
int64_t tmp=f(l,i,kk)+f(i+1,r,k-kk-1)+(a[i]-a[l-1])*(a[r]-a[i]);
if(F[l][r][k]<tmp)
{
F[l][r][k]=tmp;
pos=i;
}
}
return F[l][r][k];
}
void Path(int l,int r,int k)
{
if(k==0)
return;
for(int64_t i=l;i<r;i++)
for(int64_t kk=0;kk<k;kk++)
if(F[l][r][k]==f(l,i,kk)+f(i+1,r,k-kk-1)+(a[i]-a[l-1])*(a[r]-a[i]))
{
rs.push_back(i);
Path(l,i,kk);
Path(i+1,r,k-kk-1);
return;
}
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n>>k;
for(int64_t i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
cout<<f(1,n,k)<<"\n";
Path(1,n,k);
for(int i=0;i<rs.size();i++)
cout<<rs[i]<<' ';
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int64_t f(int64_t, int64_t, int64_t)':
sequence.cpp:16:13: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
int64_t pos;
^
sequence.cpp: In function 'int main()':
sequence.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rs.size();i++)
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |