题意:

有n个数,每个数都有价钱,连续的取可以获得len*len的利益,使利益最大。

思路:

三维DP,1、2、3维分别是第i个,剩余多少钱,从后往前连续的有几个。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr strcat
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
#include <iomanip>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
const ll INF=(1LL<<);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e2+; int a[N];
int dp[N][N][N]; void solve()
{
int n,m;
sc("%d%d",&n,&m);
for(int i=;i<=n;++i)
sc("%d",&a[i]);
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
for(int k=;k<=n;++k)
dp[i][j][k]=-inf;
dp[][m][]=;
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
for(int k=;k<=i;++k)
dp[i][j][]=max(dp[i][j][],dp[i-][j][k]);
if(j+a[i]<=m)
for(int k=;k<=i;++k)
{
// if(dp[i-1][j+a[i]][k-1]!=-inf)都可以or取max;
dp[i][j][k]=max(dp[i][j][k],dp[i-][j+a[i]][k-]+*k-);
}
}
/* for(int j=0;j<=m;++j)
for(int k=0;k<=n;++k)
pr("%3d%c",dp[i][j][k]," \n"[k==n]);
pr("-------------------------------------------\n");*/
}
int ans=;
for(int j=;j<=m;++j)
for(int k=;k<=n;++k)
ans=max(ans,dp[n][j][k]);
pr("%d\n",ans);
} int main()
{
int T;
sc("%d",&T);
while(T--)solve();
return ;
} /**************************************************************************************/
05-18 09:27