WOJ
来源:互联网 发布:ip网络广播终端 编辑:程序博客网 时间:2024/05/07 03:33
继续用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.
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
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<stdio.h>#include<string.h>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<n;i++)scanf("%d",&ques[i]);printf("%d\n",dfs(0,time,0));}return 0;}int dfs(int no,int rest,int cons){int k1,k2,max;k1=k2=max=0;if(visited[no][rest][cons]) return visited[no][rest][cons];if(no==n+1) return 0;/*printf("no:%d rest:%d cons:%d \n",no,rest,cons);*/if(rest>=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]);*/}elsevisited[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];}
- WOJ
- woj
- WOJ 1020
- WOJ 1014
- WOJ 1055
- WOJ-1402
- WOJ--1314
- WOJ-1315
- WOJ-1316
- WOJ-1100
- woj-1301
- WOJ-1167
- WOJ 1619
- woj 1538
- WOJ1416-WOJ
- WOJ-1002
- WOJ-1003
- WOJ 1011
- QT-Linguist使用方法简单介绍
- 鼠标在用户名上浮现状态卡
- 进程间共享数据
- mysql用户权限
- 用递归法实现一个十进制数据转换成二进制
- WOJ
- 在终端中打开各类文件的通用命令
- 腾讯抄你肿么办,致创业者或准创业者们!
- mysql中的unix_timestamp函数
- 项目成本评估及预算的制定
- Unix多线程编程技术
- 使用jQuery AJax 与 asp.net ashx 结合使用
- totorse cvs 用法
- Oracle常用监控SQL