开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
MyLeetCode
/
Main.java
MyLeetCode
/
Main.java
Main.java 4.24 KB
一键复制 编辑 原始数据 按行查看 历史
sunzuhan 提交于 2015年07月01日 09:38 +08:00 . fixed confict
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
<<<<<<< HEAD
private int n;
private int m;
private int[][] food;
/*
* define three Adjacent directions
* while contian down、up、right
*/
int[][] dir={{1,0},{-1,0},{0,1}};
/*
* read input data
*/
public void Input(){
Scanner input=new Scanner(System.in);
n=input.nextInt();
m=input.nextInt();
if(n==0 || m==0)
=======
private List<String> ans;
private int end;
private boolean[] vis;
private int size;
public void dfs(int[] rec,int n){
if(end==0)
>>>>>>> 32b807a3191a63c9921894f99113675c09055120
return ;
int i;
int x=0;
<<<<<<< HEAD
x++;
}
/*
* dp[i][j][3],i、j represent the location in the board, and 3th dimension
* represent the three coming state best score,while are from the Adjacent down、up、left position
*/
public int solved(){
int i,j,k;
int[][][] dp=new int[n+1][m+1][3];
=======
StringBuilder sb=new StringBuilder();
>>>>>>> 32b807a3191a63c9921894f99113675c09055120
for(i=0;i<n;i++){
x*=10;
x+=rec[i];
sb.append(rec[i]);
}
<<<<<<< HEAD
for(i=1;i<=m;i++){
/*
* handle the ith row
*/
for(j=0;j<n;j++){
dp[j][i][0]=-1;
dp[j][i][1]=-1;
dp[j][i][2]=-1;
if(food[j][i-1]!=-1){
dp[j][i][0]=dp[j][i-1][0]+food[j][i-1];
}
}
/*
* update dp[j][i][1]=max(dp[j-1][i][1]+food[j][i],dp[j-1][i-1][0]+food[j][i]);
* coming from the left position or the up position
*/
for(j=0;j<n;j++){
//the position [i][j] is allowed to be passed
if(food[j][i-1]!=-1){
dp[j][i][1]=dp[j][i][0];
if(j==0){
/*
* from the (n-1)th row down to this position
*/
if(food[n-1][i-1]!=-1 && dp[n-1][i][0]!=-1){
dp[j][i][1]=max(food[j][i-1],dp[j][i][0]);
}
}
else{
/*
* choose the larger value from up position or the left position
*/
if(food[j-1][i-1]!=-1){
dp[j][i][1]=max(food[j][i-1]+dp[j-1][i][1],dp[j][i][0]);
}
}
}
}
/*
* update dp[j][i][2] which is from the left or the down direction
*/
for(j=n-1;j>=0;j--){
//down direction is allowed to be passed
if(food[j][i-1]!=-1){
//suppose comming from the left direction
dp[j][i][2]=dp[j][i][0];
if(j==n-1){
/*
* from the 0th row up to transport the (n-1)th row,update dp[j][i]
*/
if(food[0][i-1]!=-1 && dp[0][i][0]!=-1){
dp[j][i][2]=max(food[j][i-1],dp[j][i][0]);
}
}
else{
/*
* dp[j][i][2] choose the larger which is from the down direction or the left direction
*/
if(food[j+1][i-1]!=-1){
dp[j][i][2]=max(food[j][i-1]+dp[j+1][i][2],dp[j][i][0]);
}
}
}
}
/*
* update dp[i][j][0] =max{dp[i][j][↓],dp[i][j][↑]},make the dp[i][j][0] to be the max score
* from the three direction
*/
for(j=0;j<n;j++){
dp[j][i][0]=max(dp[j][i][1],dp[j][i][2]);
}
}
int maxFood=-1;
/*
* find the best score which is in the (m-1)th column
*/
for(i=0;i<n;i++){
if(maxFood<dp[i][m][0]){
maxFood=dp[i][m][0];
=======
ans.add(sb.toString());
end--;
vis[x]=true;
for(i=0;i<n;i++){
int t=rec[i];
t++;
if(t>9)
t=0;
int y=0;
for(int j=0;j<i;j++){
y*=10;
y+=rec[j];
}
y*=10;
y+=t;
for(int j=i+1;j<n;j++){
y*=10;
y+=rec[j];
}
if(y>=0 && y<size && !vis[y]){
rec[i]=t;
dfs(rec,n);
break;
}
t=rec[i];
t--;
if(t<0)
t=9;
y=0;
for(int j=0;j<i;j++){
y*=10;
y+=rec[j];
}
y*=10;
y+=t;
for(int j=i+1;j<n;j++){
y*=10;
y+=rec[j];
}
if(y>=0 && y<size && !vis[y]){
rec[i]=t;
dfs(rec,n);
break;
>>>>>>> 32b807a3191a63c9921894f99113675c09055120
}
}
}
public void solved(int n){
end=1;
for(int i=0;i<n;i++){
end*=10;
}
size=end;
vis=new boolean[end+1];
ans=new ArrayList<String>();
int[] rec=new int[n];
for(int i=0;i<n;i++)
rec[i]=0;
dfs(rec,n);
System.out.println(size-1);
for(int i=0;i<ans.size();i++){
System.out.println(ans.get(i));
}
System.out.println();
}
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int n;
n=input.nextInt();
Main mm=new Main();
mm.solved(n);
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

leetcode代码
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/4clover/MyLeetCode.git
git@gitee.com:4clover/MyLeetCode.git
4clover
MyLeetCode
MyLeetCode
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /