博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WOJ
阅读量:5291 次
发布时间:2019-06-14

本文共 2161 字,大约阅读时间需要 7 分钟。

继续用DFS+记忆化剪枝来解决一般的dp

Description
Alex likes solving problems on WOJ (http://acm.whu.edu.cn/oak). As we all know, a beautiful balloon will appears when a 
problem is solved. Alex loves balloons, especially when they're in a consecutive column, from which he can get a sense of 
accomplishment. 
Problems on WOJ have a variety of difficulties. Hard problems cost more time, while easy ones may be "killed in 1 
second". Now we know that WOJ has N problems, numbered from 1 to N. Alex calls the solved problems in one 
consecutive column as a "successful string". The length of a successful string is the number of problems it contains. Also 
he defines the value of a successful string as the square of the string's length. Alex hopes to solve a certain number of 
problems in M time, so he can get some successful strings, now he wants to maximize the sum of all the strings' value. 

Input
The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases. 
The input consists of several test cases. Each test case starts with a line containing two integers N and M. 
Each of the following N lines contains a single integer Mi indicating the time cost on solving the i-th problem. 
(1<=N, M<=100) 
[Technical Specification] 
T is an integer, and T <= 15; 
N and M are integers, 1 <= N, M <= 100. 
Mi are integers and, 0 <= Mi <= 100 

Output
For each test case, print a single line containing a number indicating the maximum sum.

#include
#include
int visited[105][105][105];int dfs(int ,int ,int );int ques[105];int n;int main(){ int t,i,time; for(scanf("%d",&t);t;t--) { memset(visited,0,sizeof(visited)); scanf("%d %d",&n,&time); for(i=0;i
=ques[no]) k1=dfs(no+1,rest-ques[no],cons+1); k2=dfs(no+1,rest,0); if(k1>=k2) max=k1; else max=k2; if(!cons) { visited[no][rest][cons]=max; /* printf("HHHH:%d\n",visited[no][rest][cons]);*/ } else visited[no][rest][cons]=cons*2-1+max;/* printf("no:%d rest:%d cons:%d result:%d\n",no,rest,cons,visited[no][rest][cons]);*/ return visited[no][rest][cons];}

转载于:https://www.cnblogs.com/yobobobo/archive/2012/06/12/3826834.html

你可能感兴趣的文章
java使用sax解析xml
查看>>
20个常用正则表达式
查看>>
hdfs切片的计算方式
查看>>
yolo源码解析(一)
查看>>
UVA-10061 How many zero's and how many digits ? (数论)
查看>>
关于阿西莫夫
查看>>
深深自责
查看>>
Nessus安装出现localhost:8834无法访问
查看>>
Android Eclipse JNI 调用 .so文件加载【转】
查看>>
如何添加 actions
查看>>
jQuery移除或禁用html元素点击事件常用方法小结
查看>>
volatile关键字
查看>>
20180524模拟赛T3——Word
查看>>
计算机网络基础
查看>>
关于书签(BookMark)操作;
查看>>
查看Linux服务器的硬盘使用情况
查看>>
日报 18/06/20
查看>>
loj #6136. 「2017 山东三轮集训 Day4」Left
查看>>
java集合类
查看>>
学习资料
查看>>