当前位置:网站首页>Mnemonic search + state compression leetcode four hundred and sixty-four
Mnemonic search + state compression leetcode four hundred and sixty-four
2022-06-10 04:33:00 【Lu 727】
public static boolean canIWin(int maxChoosableInteger, int desiredTotal) {
int[] dp=new int[1<<maxChoosableInteger];// Will you win in a certain state
// The sum is less than the target , Will lose
if(desiredTotal>(1+maxChoosableInteger)*maxChoosableInteger/2) return false;
return dfs(dp,0,maxChoosableInteger,desiredTotal,0);
}
static boolean dfs(int[] dp,int sum,int maxChoosableInteger,int desiredTotal,int state){
// If the current state has been traversed , return
if(dp[state]!=0) {
if(dp[state]==1)
return true;
else return false;
}
// Look for unselected numbers
for(int j=0;j<maxChoosableInteger;j++){
if((state&(1<<j))!=0) continue;
// If the number meets the conditions, you will win
if(sum+j+1>=desiredTotal){
dp[state]=1;
return true;
}
// Otherwise, judge whether the other party will lose
if(!dfs(dp,sum+j+1,maxChoosableInteger,desiredTotal,state|(1<<j))){
dp[state]=1;
return true;
}
}
// You can't make yourself win or your opponent lose , Then you lose
dp[state]=-1;
return false;
}边栏推荐
- golang学习之六:中的文件操作
- Descriptor ready condition
- ThreadLocal basic and advanced use
- Acl2022 | the introduction of comparative learning to add negative samples to the generation process enables the model to effectively learn knowledge at different levels
- 超好用的 Chrome 插件!
- [in depth study of 4g/5g/6g topic -27]: 5g NR startup process 4.5 - RRC connection response message msg4, first scheduling of PUCCH uplink control channel, UCI and HARQ response
- Basic methods of stack and related problems
- Distributed data object: HyperTerminal 'global variable'
- Common database field type mapping relationships
- Eight part essay ceiling! (PDF HD download)
猜你喜欢
![[graduation project 2] intelligent range hood system based on stm32](/img/b0/2ab9f22c939198f3cd5fcf11d87998.png)
[graduation project 2] intelligent range hood system based on stm32

mindspore1.6conda安装gpu版本验证失败

5分钟学会本地Pypi源搭建

Log management of MySQL database

TCP (sliding window, flow control)

超好用的 Chrome 插件!

Distributed data object: HyperTerminal 'global variable'
![[Error] anonymous type with no linkage used to declare function ‘bool InitSLinkList](/img/18/debeb3e1125de7f172a5cca3bd0d83.png)
[Error] anonymous type with no linkage used to declare function ‘bool InitSLinkList

Basic methods of stack and related problems

分布式数据对象:超级终端的'全局变量'
随机推荐
城市/学校/专业,哪个在选大学时最重要? | 每日趣闻
497. 非重叠矩形中的随机点
【深度学习】《PyTorch入门到项目实战》(十一):卷积层
Fastapi-16-page beautification-1
[android l]seandrod security enhancement background summary and impact
Email: analysis of wrong arrangement
FastApi-17-页面美化-2
Basic methods of stack and related problems
Temporary global variables and iritemp database
. Net C Foundation (7): interface - how people interact with cats
深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)
S系列·向文本文件新增数据并且不添加重复值
Maximum difference between left and right maximum values
Su Tao: application of counter sample technology in the field of Internet Security
[in depth study of 4g/5g/6g topic -26]: 5g NR startup process 4.4 - scheduling of RRC connection response message msg4 (rrcsetup authorization) and detailed explanation of message content
Figure out the difference between firmware, driver and software
TCP (sliding window, flow control)
IO被谁吃了?
Common database field type mapping relationships
Yyds dry goods inventory solution sword finger offer: rectangular coverage