题目:
分析:
和486. 预测赢家完全一样。
见:https://blog.csdn.net/weixin_42721412/article/details/104189607
这次用dp来做吧。
代码:dp竟然超时。。。
class Solution {
public:
int A[501][501];
int f(int x,int y,vector<int> p)
{
if(A[x][y]) return A[x][y];
if(x==y) return p[x];
A[x][y]=max(p[x]-f(x+1,y,p),p[y]-f(x,y-1,p));
return A[x][y];
}
bool stoneGame(vector<int>& p) {
memset(A,0,sizeof(A));
if(f(0,p.size()-1,p)>0) return true;
return false;
}
};