dp[i][j]:从前i个中挑出某些且cost不超过j的最大val。

dp[i][j]:应该有1到i-1的dp[k][j-?]来更新!!

 /*
DP
dp[i][j]:从前i个中挑出某些且cost不超过j的最大val。
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-;
int dp[ maxn ][ maxn ];
int a[ maxn ];
int main(){
int T;
scanf("%d",&T);
while( T-- ){
int n,sum;
scanf("%d%d",&n,&sum);
int MinCost = inf;
for( int i=;i<=n;i++ ){
scanf("%d",&a[i]);
if( a[i]<MinCost ) MinCost = a[i];
}
if( MinCost>sum ){
printf("0\n");
continue;
}
if( MinCost==sum ){
puts("");
continue;
}
int ans = ;
memset( dp,,sizeof( dp ) );
for( int i=;i<=n;i++ ){
for( int j=;j<=sum;j++ ){
int cnt = ;
for( int k=;k<=i;k++ ){
cnt += a[ i+-k ];
if( cnt>j ) break;
dp[i][j] = max( dp[i][j],dp[i-k][j-cnt]+k*k );
}
dp[i][j] = max( dp[i][j],dp[i-][j] );
ans = max( ans,dp[i][j] );
}
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. 模糊测试(Fuzz testing)
  2. expr
  3. ubuntu缺少libgtk-x11-2.0.so.0的解决办法
  4. 【洛谷P1080】国王游戏
  5. C# ManualResetEvent的使用
  6. 使用Spring的Property文件存储测试数据 - 添加测试数据
  7. 第二回 认识CDN
  8. Unity3D鼠标点击物体产生事件
  9. jquery keyup 在IOS设备上输入中文时不触发
  10. Python输入输出练习,运算练习,turtle初步练习
  11. JAVA死锁
  12. mysql一些使用技巧
  13. [译文] SQL JOIN,你想知道的应该都有
  14. day03笔记
  15. __nw_connection_get_connected_socket_block_invoke Connection has no connected handle 解决办法
  16. Webapi创建和使用 以及填坑(三)
  17. Linux中FTP的一点理解
  18. Python(四) 列表元组
  19. MySQL日志——Undo | Redo【转】
  20. [c/c++] programming之路(2)、kill QQ,弹出系统对话框,吃内存等

热门文章

  1. ubuntu 更新软件源
  2. dom0级事件和dom2级事件
  3. Map的三种遍历方式
  4. spring中jdbc的配置
  5. 考虑virtual函数以外的其它选择
  6. 谈谈Nullable&lt;T&gt;的类型转换问题
  7. 一款jquery写出来的tab切换
  8. 如何保证写出来的程序没BUG
  9. phpstorm 自定义函数配置
  10. 使用WebGL实现一个Viewer来显示STL文件