- 博客(9)
- 资源 (1)
- 收藏
- 关注
原创 【动态规划】求二维矩阵的最大和子矩阵
题目描述:有一个正整数和负整数组成的NxN矩阵,请编写代码找出元素总和最大的子矩阵。请尝试使用一个高效算法。给定一个int矩阵mat和矩阵的阶数n,请返回元素总和最大的子矩阵的元素之和。保证元素绝对值小于等于100000,且矩阵阶数小于等于200。测试用例:[[1,2,-3],[3,4,-5],[-5,-6,-7]],3返回:10题目解析:
2016-05-30 21:06:14 9334
原创 【动态规划】minimum-path-sum
题目描述:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or rig
2016-05-30 19:28:11 665
原创 【动态规划】放苹果
题目描述:把 M 个同样的苹果放在 N 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?注意:5、1、1 和 1、5、1 是同一种分法,即顺序无关。输入描述:输入包含多组数据。每组数据包含两个正整数 m和n(1≤m, n≤20)。输出描述:对应每组数据,输出一个整数k,表示有k种不同的分法。
2016-05-29 20:55:02 1590
原创 【动态规划】爬台阶
题目描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?我的代码:public class
2016-05-29 20:14:15 823
原创 【动态规划】独一无二的路径
题目描述:有一个XxY的网格,一个机器人只能走格点且只能向右或向下走,要从左上角走到右下角。请设计一个算法,计算机器人有多少种走法。给定两个正整数int x,int y,请返回机器人的走法数目。保证x+y小于等于12。输入:2,2输出:2我的代码:import java.util.*;public class Robot { /** * 计算一
2016-05-29 20:09:17 439
原创 一些很有用的小函数(自己写的)
1.求一个矩阵乘法和矩阵乘方 /** * 矩阵乘法 * @param A x*y的矩阵 * @param B y*z的矩阵 * @return C x*z的矩阵 */ public static int[][] multi(int A[][], int B[][]) { // A的行数 int x = A.length; // A的列数 = B的
2016-05-21 16:38:55 328
原创 用数组代替递归极大提高算法时间
以斐波那契数列为例,常见的写法如下:import java.util.Scanner;public class Main { public static int getNum(int n) { if(n == 1 || n == 2){ return n; } else return getNum(n-1) + getNum(n-2); } public s
2016-05-21 16:29:59 559
原创 面试常用排序算法
public class Sort { // 插入排序 public void insertSort(int array[], int length) { // 从1开始遍历 for (int i = 1; i < length; i++) { int j = i - 1; //temp用来记录需要插入的值 int temp = array[i]; for (;
2016-05-18 19:10:15 256
原创 编程题中需要注意的问题
1.Java中怎么对一个List进行排序Collections.sort(list)2.怎样高逼格的判断一个数是奇数还是偶数if((num&1)==0) //是偶数else //是奇数//注意 & 的优先级小于 ==
2016-05-18 10:24:19 433
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人