hdoj1244_Max Sum Plus Plus Plus(dp)
【hdoj1244_Max Sum Plus Plus Plus(dp)】题目中先后的意思是顺序前后的意思
#include
#include
#includeusing namespace std;
long long num[10100], len[100], table[10100][100], sum[10100];
long long dp(int n,int m)
{
memset(table, 0, sizeof(table));
for (int i = 1;
i <= n;
i++)
for (int j = 1;
j <= m;
j++)
{
table[i][j] = table[i - 1][j];
if (i >= len[j])
{
table[i][j] = max(table[i][j], table[i - len[j]][j - 1] + sum[i] - sum[i - len[j]]);
}
}
return table[n][m];
}int main()
{
int n;
while (cin >> n&&n)
{
int m;
cin >> m;
for (int i = 1;
i <= m;
i++)
cin >> len[i];
sum[0] = 0;
for (int i = 1;
i <= n;
i++)
{
cin >> num[i];
sum[i] = sum[i - 1] + num[i];
}
cout << dp(n, m) << endl;
}
return 0;
}
推荐阅读
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- 051:指针练习(MyMax)
- numpy中np.nanmax和np.max的区别及坑
- 29th|29th May Learning summary of Blockchain
- 我们真的读懂鸡汤文了吗()
- softmax损失函数-交叉熵
- 6月|6月 summer is coming
- 【leetcode】数组
- Max|Max retries exceeded with URL错误解决方法
- LeetCode|LeetCode 437. Path Sum III