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