首页 > 代码库 > NOIP201006乌龟棋(C++)
NOIP201006乌龟棋(C++)
#include <iostream>
using namespace std;
int dp[50][50][50][50] = {0};
int b[5]={0};
int max(int a, int b, int c, int d)
{
int m = a;
if(b>m) m = b;
if(c>m) m = c;
if(d>m) m = d;
return m;
}
int main()
{
int n,m;
cin >> n >> m;
int a[n];
for(int i=0; i<n; i++)
{
cin >> a[i];
}
for(int i=0; i<m; i++)
{
cin >> b[0];
b[b[0]]++;
}
int maxScore = 0;
for(int t=0; t<=b[1]; t++)
{
for(int i=0; i<=b[2]; i++)
{
for(int j=0; j<=b[3]; j++)
{
for(int k=0; k<=b[4]; k++)
{
maxScore = 0;
if(t) maxScore=maxScore>dp[t-1][i][j][k]?maxScore:dp[t-1][i][j][k];
if(i) maxScore=maxScore>dp[t][i-1][j][k]?maxScore:dp[t][i-1][j][k];
if(j) maxScore=maxScore>dp[t][i][j-1][k]?maxScore:dp[t][i][j-1][k];
if(k) maxScore=maxScore>dp[t][i][j][k-1]?maxScore:dp[t][i][j][k-1];
dp[t][i][j][k]=maxScore+a[t+2*i+3*j+4*k];
}
}
}
}
cout << dp[b[1]][b[2]][b[3]][b[4]];
return 0;
}
NOIP201006乌龟棋(C++)