2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

时间:2023-01-06 14:42:41

.navbar-nav > li.active > a {
background-image: none;
background-color: #058;
}

.navbar-inverse #navbar > .navbar-nav > li > a:hover,
.navbar-inverse #navbar > .navbar-nav > li > a:focus {
background-image: none;
background-color: #069;
}

.navbar-inverse .navbar-nav > .open > a,
.navbar-inverse .navbar-nav > .active > a,
.navbar-inverse .navbar-nav > .open > a:hover,
.navbar-inverse .navbar-nav > .open > a:focus {
background-image: none;
background-color: #058;
}

.navbar-brand {
padding: 0;
}

.navbar-inverse .dropdown-menu {
background-color: #0696cb;
}

.navbar-inverse .dropdown-menu > li > a:hover,
.navbar-inverse .dropdown-menu > li > a:focus {
background-image: none !important;
background-color: #058 !important;
}

.navbar-brand > img {
height: 48px;
width: auto;
}

.footer {
width: 100%;
padding: 5px 20px;
margin-top: 20px;
border-top: 1px solid #e7e7e7;
background-color: #F0F0F0;
text-align: center;
}

.table-center th, .table-center td {
text-align: center;
}

.table-middle th, .table-middle td {
vertical-align: middle !important;
}

.table .table {
background-color: inherit;
}

.operate > a + a {
margin-left: 10px;
}

.form-inline {
margin-bottom: 10px;
}

.pull-left > ul.pagination, .pull-right > ul.pagination {
margin: 0;
}

.problem-widget {
margin-top: 30px;
}

.problem-widget-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
color: #333;
}

.problem-widget pre {
padding: 0;
margin: 0;
font-size: 13px;
line-height: 1.42857143;
color: #333;
word-break: break-word;
white-space: pre-wrap;
background-color: transparent;
border: none;
overflow: visible;
}

.problem-widget-content {
display: block;
padding: 9.5px;
margin: 0 0 10px;
font-size: 14px;
line-height: 1.42857143;
color: #333;
word-break: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
}

.clipboard {
position: relative;
}

.clipboard > .copy {
display: none;
float: right;
padding: 3px 6px;
}

.clipboard:hover > .copy {
display: inline-block;
}

.problem-footer {
text-align: center;
font-size: 16px;
font-weight: bold;
margin-top: 20px;
}

.problem-footer .btn + .btn {
margin-left: 40px;
}

img.country-flag {
width: 42px;
height: 27px;
}

#status-form input {
width: 100px;
}

#status-form input[type="submit"] {
padding: 5px;
width: 50px;
}

.status-nav {
text-align: center;
}

.status-nav > a + a {
margin-left: 30px;
}

.required {
margin-right: -11px;
padding-left: 4px;
color: red;
}

.required::after {
content: '*';
}

.label-text {
padding-top: 7px;
margin-bottom: 0;
}

#check-code {
text-align: center;
padding: 7px 0;
}

.form-error {
color: #d00;
font-size: 1.2em;
}

.problem-status {
width: 70px;
display: inline-block;
}

.problem-status-number {
font-size: .8em;
color: #cc0000;
}

.form-group > .input-group + .input-group {
margin-top: 5px;
}

#contest-info {
font-size: 1.1em;
}

#contest-info p {
margin-bottom: 5px;
}

#contest-info h2 {
font-size: 24px;
}

.text-red {
color: #f00;
}

.text-green {
color: #080;
}

.text-orange {
color: #f90;
}

.text-purple {
color: #808;
}

#contest-list img {
width: 24px;
}

#contest-list img {
margin-left: 8px;
}

#contest-list .contest-time {
font-size: 10px;
}

.no-data {
font-family: "times new roman", serif;
margin-top: -20px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-top: none;
font-size: 64px;
color: #aaa;
text-align: center;
padding: 80px;
}

.no-body-data {
font-family: "times new roman", serif;
border-top: 2px solid #ccc;
font-size: 64px;
color: #aaa;
text-align: center;
padding: 80px;
}

.panel .nav-tabs {
margin-bottom: 15px;
}

.badge-statistic {
font-size: 15px;
padding: 3px 12px;
background-color: green;
}

#contest-ranklist .ranklist-problemid {
font-size: .8em;
padding-top: 2px;
padding-bottom: 2px;
}
#contest-ranklist .ranklist-problem {
font-size: .8em;
padding-top: 2px;
padding-bottom: 2px;
}
#contest-ranklist .ranklist-problem > .text-green {
font-weight: bold;
}

.countdown {
display: inline-block;
}

.pending {
padding: 50px;
font-size: 36px;
text-align: center;
}

.countdown > span {
padding: 2px;
border: 1px solid #ddd;
border-radius: 2px;
background: #f8f8f8;
}

#concern-team {
margin-top: -10px;
margin-bottom: 5px;
}

.form-footer {
text-align: center;
}

.form-footer > .btn {
min-width: 80px;
}

.form-footer > .btn + .btn {
margin-left: 60px;
}

.topic-reply {
margin: 0;
padding: 5px;
}

.topic-reply > div > img {
width: 100%;
height: auto;
max-height: 80px;
max-width: 80px;
}

.topic-reply:hover {
background-color: #fcfcfc;
}

.topic-reply + .topic-reply {
margin-top: 10px;
}

.topic-main {
border: 1px solid #ccc;
border-radius: 4px;
padding: 0;
}

.topic-main:before, .topic-main:after {
position: absolute;
top: 11px;
left: -16px;
right: 100%;
width: 0;
height: 0;
display: block;
content: " ";
border-color: transparent;
border-style: solid solid outset;
pointer-events: none;
}

.topic-main:before {
border-right-color: #ccc;
border-width: 8px;
}

.topic-main:after {
border-width: 7px;
border-right-color: #eee;
margin-top: 1px;
margin-left: 2px;
}

.topic-reply-author {
background-color: #eee;
border-bottom: 1px solid #ccc;
padding: 8px;
}

.topic-reply-title {
font-size: 17px;
padding: 5px 10px 0;
}

.topic-reply-content {
padding: 10px;
word-break: break-word;
}

.check-code > input {
position: relative;
}

.check-code > img {
position: absolute;
z-index: 100;
right: 5px;
height: 36px;
top: 5px;
}

#contest-info, #problem-info {
margin-bottom: 20px;
}

#contest-info h1, #problem-info h1 {
margin-right: 30px;
display: inline-block;
color: #333;
}

#contest-info .status-pending, #contest-info .status-runing, #contest-info .status-ended {
border-radius: 4px;
padding: 3px 6px;
color: #fff;
}
#contest-info .status-pending {
background-color: #5bc0de;
}
#contest-info .status-runing {
background-color: green;
}
#contest-info .status-ended {
background-color: gray;
}

#contest-info #current-time {
margin-left: 10px;
}

#problem-info .problem-statistic {
display: inline-block;
margin-right: 40px;
}

.level0 {
color: #000 !important;
}

.level1 {
color: #9E9E9E !important;
}

.level2 {
color: #8BC34A !important;
}

.level3 {
color: #4CAF50 !important;
}

.level4 {
color: #00BCD4 !important;
}

.level5 {
color: #3F51B5 !important;
}

.level6 {
color: #9C27B0 !important;
}

.level7 {
color: #FF9800 !important;
}

.level8 {
color: #F06292 !important;
}

.level9 {
color: #FF0000 !important;
}

.link-above-table {
margin-bottom: 5px;
}

#source-modal > .modal-lg {
width: 604px;
margin: 10px auto;
}

#source-modal .modal-body {
padding: 0;
}

#source-modal .modal-body > pre {
margin: 0;
}

#room {
margin-bottom: 10px;
}

#room .my-room {
font-weight: bold;
color: green;
}

#contest-pending {
font-size: 2em;
text-align: center;
padding: 50px;
border: 1px solid #008cba;
border-radius: 4px;
}

.table > thead > tr > th, .table > tbody > tr > td {
vertical-align: middle;
}

#navbar .countdown {
margin-top: 16px;
color: #fff;
}

#navbar .countdown > span {
border-color: #069;
background-color: #07a
}

.clock, .countdown {
display: none;
}

img.ac-tired {
margin-left: 15px;
}

#data-text{
height: 500px;
}

#contest-hackstatus > tbody {
display: none;
}
#contest-hackstatus > tbody:first-child {
display: block;
}
#show-all-hackstatus {
display: none;
}

#global-message, #contest-message {
display: none;
}

.form-group .addon > select {
display: inline-block;
width: 70%;
}

.form-group .addon > select + span {
font-size: 1.6em;
vertical-align: middle;
margin-left: 2px;
}

.form-horizontal .form-group .row {
margin: 0;
}

.form-horizontal .form-group .row > div {
padding: 0;
}

fieldset + fieldset {
margin-top: 20px;
}

div.address #address {
margin-top: 5px;
}

.nav-tabs {
margin-bottom: 10px;
}

table.contest-register td {
border: none !important;
}

table.contest-register tr > td:first-child {
width: 40%;
text-align: right;
padding-right: 10%;
}

.h1-align {
height: 69px;
padding-top: 25px;
padding-bottom: 10px;
text-align: right;
}
.h3-align {
height: 56px;
padding-top: 10px;
padding-bottom: 10px;
text-align: right;
}
@media (max-width:768px) {
.h1-align, .h3-align {
text-align: left;
}
}

.form-tooltip {
padding-top: 8px;
padding-left: 0;
margin-left: -8px;
}

.mb10 {
margin-bottom: 10px;
}

table#contest-time {
margin-top: 6px;
}

table#contest-time td {
padding: 2px 5px 0 0;
}

.markdown {
white-space: pre-wrap;
word-break: break-word;
}
.markdown.marked {
white-space: normal;
}

#solutions {
border: 2px solid #008cba;
box-shadow: 4px 4px 8px #ccc;
}
#solutions > .solution {
padding: 10px;
}
#solutions > .solution + .solution {
border-top: 1px dashed #888;
}
#solutions > .solution > .solution-title span.status {
font-size: 18px;
margin-right: 4px;
}
#solutions > .solution > .solution-title > div.text-right {
padding: 5px 20px;
}
#solutions > .solution > .solution-provider {
font-size: 1.5em;
}
#solutions > .solution > .solution-bestcoder {
margin: 10px 0 0;
font-size: 1.5em;
}
#solutions > .solution > .solution-bestcoder > div {
white-space: nowrap;
}
#solutions > .solution > .solution-bestcoder > div > a {
color: white !important;
}
#solutions > .solution > .solution-bestcoder > .no1 {
background: red;
}
#solutions > .solution > .solution-bestcoder > .no2 {
background: orange;
}
#solutions > .solution > .solution-bestcoder > .no3 {
background: purple;
}
#solutions > .solution > .solution-body {
margin-top: 15px;
}

#system-message {
border: 1px solid #008cba;
padding: 8px;
margin-right: -15px;
}
#system-message > h3 {
color: #008cba;
text-align: center;
border-bottom: 1px solid #888;
margin: -5px -8px 8px;
padding: 5px;
}
#tops {
border: 1px solid #008cba;
margin-top: 20px;
margin-right: -15px;
}
#tops > h3 {
color: #008cba;
text-align: center;
border-bottom: 1px solid #888;
margin: 5px 0 0;
padding: 5px;
}
#tops > table {
margin-bottom: 0;
}
#weibo {
border: 1px solid #008cba;
margin-top: 20px;
margin-right: -15px;
}

#code-style {
float: right;
margin-right: 20px;
}

#hack-error {
color: #f00;
font-size: 1.2em;
float: left;
}

#message-box {
position: fixed;
right: 40px;
bottom: 20px;
width: 500px;
max-height: 250px;
overflow-y: auto;
}
#message-box > li.list-group-header {
font-size: 1.2em;
font-weight: bold;
border-bottom: 3px solid #008cba;
color: #008cba;
padding: 10px;
}
#message-box > li > .time {
float: right;
}

.link-icon:hover, .link-icon:active, .link-icon:focus {
text-decoration: none;
}
.link-icon {
margin-left: 10px;
}

#profile-heading {
margin: 0;
padding: 10px;
background-color: #f2fcff;
}
#profile-heading .bigggger {
font-size: 4em;
padding: 20px 40px 20px 5px;
color: #000;
}
#profile-school > a {
font-size: 1.4em;
margin-left: 5px;
}
#profile-motto {
font-size: 1.2em;
color: #444;
font-style: italic;
}

.fa-spin, .fa-pulse {
vertical-align: middle;
margin-left: 5px;
font-size: 16px;
}

.badge a {
color: #fff;
}

#rating-chart-wrapper {
min-width: 0px;
overflow: auto;
}
#rating-chart {
min-width: 768px;
}

.twitter-typeahead {
display: block !important;
}
.typeahead {
background-color: #fff;
}

.typeahead:focus {
border: 2px solid #0097cf;
}

.tt-query {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

.tt-hint {
color: #999
}

.tt-menu {
width: 100%;
margin: 0 0 12px;
padding: 8px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}

.tt-suggestion {
padding: 3px 20px;
font-size: 18px;
line-height: 24px;
}

.tt-suggestion:hover {
cursor: pointer;
color: #fff;
background-color: #0097cf;
}

.tt-suggestion.tt-cursor {
color: #fff;
background-color: #0097cf;

}

.tt-suggestion p {
margin: 0;
}

img{
max-width: 100%;
}

.index-banner {
display: block;
margin: 0 -15px;
}
.index-banner > img {
width: 100%;
}
-->

度度熊与邪恶大魔王

Accepts: 3021
Submissions: 18787
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Problem Description
度度熊为了拯救可爱的公主,于是与邪恶大魔王战斗起来。 邪恶大魔王的麾下有n个怪兽,每个怪兽有a[i]的生命值,以及b[i]的防御力。 度度熊一共拥有m种攻击方式,第i种攻击方式,需要消耗k[i]的晶石,造成p[i]点伤害。 当然,如果度度熊使用第i个技能打在第j个怪兽上面的话,会使得第j个怪兽的生命值减少p[i]-b[j],当然如果伤害小于防御,那么攻击就不会奏效。 如果怪兽的生命值降为0或以下,那么怪兽就会被消灭。 当然每个技能都可以使用无限次。 请问度度熊最少携带多少晶石,就可以消灭所有的怪兽。
Input
本题包含若干组测试数据。 第一行两个整数n,m,表示有n个怪兽,m种技能。 接下来n行,每行两个整数,a[i],b[i],分别表示怪兽的生命值和防御力。 再接下来m行,每行两个整数k[i]和p[i],分别表示技能的消耗晶石数目和技能的伤害值。 数据范围: 1<=n<=100000 1<=m<=1000 1<=a[i]<=1000 0<=b[i]<=10 0<=k[i]<=100000 0<=p[i]<=1000
Output
对于每组测试数据,输出最小的晶石消耗数量,如果不能击败所有的怪兽,输出-1
Sample Input
Copy
1 2
3 5
7 10
6 8
1 2
3 5
10 7
8 6
Sample Output
Copy
6
18
就是一个完全背包,每个怪兽可以分开算,最后把答案加起来就是总的答案;由于怪兽的防御值范围很小,可以预处理出每一组技能下打死不同生命、不同防御值的怪物消耗的最少晶石,对于每个怪物直接在其中取答案,比对于每个怪物求一次要快很多。
自己的代码&讲解:(太丑 了,什么一直求到2*maxa也没谁了。。)
 /*
ans[i][j][b]表示防御力为b的怪物
表示用前i种技能,造成恰好j的伤害消耗的最小晶石
ans[i][j][b]=min{ans[i-1][j-x*(p[i]-b)]+x*k[i]}
x表示第i种技能取x个(0<=x*(p[i]-b)<=j)
优化:http://blog.csdn.net/wumuzi520/article/details/7014830
ans[i][j][b]=min(ans[i-1][j][b],ans[i][j-(p[i]-b)][b]+k[i]【j>=p[i]-b】)
=>ans[j][b]=min(ans[j][b],ans[j-(p[i]-b)][b]+k[i] **i从小到大
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n,m;
LL maxb,maxp,bx,maxa;
LL a[],b[];
LL ans[][];
LL k[],p[],ans1;
int main()
{
LL i,j,t,ze=(long long);
while(scanf("%lld%lld",&n,&m)==)
{
maxb=;maxp=;maxa=;
for(i=;i<=n;i++)
{
scanf("%lld%lld",&a[i],&b[i]);
maxb=max(maxb,b[i]);
maxa=max(maxa,a[i]);
}
for(i=;i<=m;i++)
{
scanf("%lld%lld",&k[i],&p[i]);
maxp=max(maxp,p[i]);
}
maxa=max(maxa,maxp);
/*
去掉以上这句,会让类似
1 1
45 10
4164 327
的数据得出错误结果
*/
if(maxb>=maxp)
{
printf("-1\n");
continue;
}
memset(ans,0x3f,sizeof(ans));
memset(ans[],,sizeof(ans[]));
for(bx=;bx<=maxb;bx++)
{
for(i=;i<=m;i++)
for(j=max(ze,p[i]-bx);j<=*maxa;j++)
// {
//if(j>=p[i]-bx)
ans[j][bx]=min(ans[j][bx],ans[j-p[i]+bx][bx]+k[i]);
// }
t=0x3f3f3f3f;
for(j=*maxa;j>=;j--)
{
t=min(t,ans[j][bx]);
ans[j][bx]=min(ans[j][bx],t);
}
}
ans1=;
for(i=;i<=n;i++)
ans1+=ans[a[i]][b[i]];
printf("%lld\n",ans1); }
return ;
}

题解:2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)