Language: C++

#include <cstdio>#include <iostream>#include <vector>#include <list>#include <cmath>#include <fstream>#include <algorithm>#include <string>#include <queue>#include <set>#include <map>#include <complex>#include <iterator>#include <cstdlib>#include <cstring>#include <sstream>
using namespace std;
#define EPS (1e-10)#define EQ(a,b) (abs((a) - (b)) < EPS)#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
typedef complex<double> P;typedef pair<P,P> Edge;typedef long long ll;
const double PI=4*atan(1.0);
//#define RED_FILE
#ifdef RED_FILEifstream ifs("input.txt");ofstream ofs("output.txt");#define cin ifs#define cout ofs#endif
// dp[idx][prv]idxÜÅÅidx-1ÌlªprvÌÆ«ìêéÅåÌcurÌlint dp[101][321];
int main(){
&#160; &#160; int t;&#160; &#160; cin>>t;&#160; &#160; while(t--){&#160; &#160; &#160; &#160; memset(dp,0,sizeof(dp));&#160; &#160; &#160; &#160; int n;&#160; &#160; &#160; &#160; cin>>n;&#160; &#160; &#160; &#160; int a[101];&#160; &#160; &#160; &#160; for(int i = 0; i < n; i++)&#160; &#160; &#160; &#160; &#160; &#160; cin>>a[i];&#160; &#160; &#160; &#160; if(n==1){&#160; &#160; &#160; &#160; &#160; &#160; cout<<a[0]<<endl;&#160; &#160; &#160; &#160; &#160; &#160; continue;&#160; &#160; &#160; &#160; }&#160; &#160; &#160; &#160; dp[0][a[0]]=a[1];&#160; &#160; &#160; &#160; for(int i = 1; i < n-1; i++){&#160; &#160; &#160; &#160; &#160; &#160; for(int j = 0; j < 321; j++){&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // JÚ³¹é&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(dp[i-1][j]-1>=0)&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; dp[i][dp[i-1][j]-1]=max(dp[i][dp[i-1][j]-1],j+a[i+1]);&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // JÚ³¹È¢&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; dp[i][dp[i-1][j]]=max(dp[i][dp[i-1][j]],a[i+1]);&#160; &#160; &#160; &#160; &#160; &#160; }&#160; &#160; &#160; &#160; }&#160; &#160; &#160; &#160; int maxNum=0;&#160; &#160; &#160; &#160; for(int i = 0; i < 321; i++){&#160; &#160; &#160; &#160; &#160; &#160; maxNum=max(dp[n-2][i],maxNum);&#160; &#160; &#160; &#160; }&#160; &#160; &#160; &#160; //for(int i = 0; i < 321; i++){&#160; &#160; &#160; &#160; // &#160; &#160;for(int j = 0; j <321; j++){&#160; &#160; &#160; &#160; // &#160; &#160; &#160; &#160;if(dp[n-2][i][j]){&#160; &#160; &#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160;maxNum=max(maxNum,j);&#160; &#160; &#160; &#160; // &#160; &#160; &#160; &#160;}&#160; &#160; &#160; &#160; // &#160; &#160;}&#160; &#160; &#160; &#160; //}&#160; &#160; &#160; &#160; cout<<maxNum<<endl;&#160; &#160; }&#160; &#160; return 0;}

//bool dp[101][321][321];////int main(){//// &#160; &#160;int t;// &#160; &#160;cin>>t;// &#160; &#160;while(t--){// &#160; &#160; &#160; &#160;memset(dp,0,sizeof(dp));// &#160; &#160; &#160; &#160;int n;// &#160; &#160; &#160; &#160;cin>>n;// &#160; &#160; &#160; &#160;int a[101];// &#160; &#160; &#160; &#160;for(int i = 0; i < n; i++)// &#160; &#160; &#160; &#160; &#160; &#160;cin>>a[i];// &#160; &#160; &#160; &#160;if(n==1){// &#160; &#160; &#160; &#160; &#160; &#160;cout<<a[0]<<endl;// &#160; &#160; &#160; &#160; &#160; &#160;continue;// &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160;dp[0][a[0]][a[1]]=true;// &#160; &#160; &#160; &#160;for(int i = 1; i < n-1; i++){// &#160; &#160; &#160; &#160; &#160; &#160;for(int j = 0; j < 321; j++){// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;for(int k = 0; k < 321; k++){// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;if(dp[i-1][j][k]){// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;if(k-1>=0)// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;dp[i][k-1][j+a[i+1]]=true;// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;dp[i][k][a[i+1]]=true;// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160;int maxNum=0;// &#160; &#160; &#160; &#160;for(int i = 0; i < 321; i++){// &#160; &#160; &#160; &#160; &#160; &#160;for(int j = 0; j <321; j++){// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;if(dp[n-2][i][j]){// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;maxNum=max(maxNum,j);// &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160;}// &#160; &#160; &#160; &#160;cout<<maxNum<<endl;// &#160; &#160;}//// &#160; &#160;return 0;//}

Compiler output:
a.cc:1:18: warning: extra tokens at end of #include directive
    1 | #include <cstdio>#include <iostream>#include <vector>#include <list>#include <cmath>#include <fstream>#include <algorithm>#include <string>#include <queue>#include <set>#include <map>#include <complex>#include <iterator>#include <cstdlib>#include <cstring>#include <sstream>
      |                  ^
a.cc:7:25: warning: extra tokens at end of #ifdef directive
    7 | #ifdef RED_FILEifstream ifs("input.txt");ofstream ofs("output.txt");#define cin ifs#define cout ofs#endif
      |                         ^~~
a.cc:7: error: unterminated #ifdef
    7 | #ifdef RED_FILEifstream ifs("input.txt");ofstream ofs("output.txt");#define cin ifs#define cout ofs#endif
a.cc:4:9: error: 'complex' does not name a type
    4 | typedef complex<double> P;typedef pair<P,P> Edge;typedef long long ll;
      |         ^~~~~~~
a.cc:4:35: error: 'pair' does not name a type
    4 | typedef complex<double> P;typedef pair<P,P> Edge;typedef long long ll;
      |                                   ^~~~
a.cc:5:19: error: 'atan' was not declared in this scope
    5 | const double PI=4*atan(1.0);
      |                   ^~~~