ZOJ Problem Set - 2297 Survival [상압 dp]
제목: 몬스터를 주면 두 가지 값이 있습니다. 그를 때리는 데 소비하는 피와 증가할 수 있는 피가 있습니다. 그리고 한 boss가 있습니다. 몬스터를 모두 때려죽인 후에야 boss를 칠 수 있습니다. 혈액량이 0보다 적으면 죽을 수도 있고 100보다 크면 안 됩니다.
분석: 정의 상태: dp[st], st 상태에서의 혈액량을 나타낸다.
그리고 이동: dp[st]=max(dp[st], dp[st&~(1<초기화를 시작할 때 반드시 초기화를 시작해야 합니다. 그렇지 않으면 오류가 발생하기 쉽습니다.
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const long long N = 22;
const int inf = 0x3f3f3f3f;
int dp[1<<N];
pair<int,int> p[N];
int main()
{
int n,boss;
while(~scanf("%d",&n) && n)
{
n--;
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
p[i]=make_pair(x,y);
}
scanf("%d",&boss);
memset(dp,0,sizeof(dp));
int ans = 0;
dp[0]=100;
for(int st=1;st<(1<<n);st++)
{
dp[st]=-inf; //
for(int j=0;j<n;j++)
if(st&(1<<j)&&dp[st&~(1<<j)]>=p[j].first)
{
dp[st]=max(dp[st],dp[st&~(1<<j)]-p[j].first+p[j].second);
if(dp[st]>100)
dp[st]=100;
}
}
if(dp[(1<<n)-1]>=boss)
puts("clear!!!");
else
puts("try again");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Access Request, Session and Application in Struts2If we want to use request, Session and application in JSP, what should we do? We can obtain Map type objects such as Req...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.