参数目录化,就是将 类似 http://www.abc.com/store/store.aspx?id=1024 这样的网址,对外改为 http://www.abc.com/1024。
要实现这种功能,可以用以下三种方式(应该不仅限这三种吧!)
1、用微软的 Microsoft URL 重写模块 2.0,但只能给IIS7使用,IIS6不行。
64位:
http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=1b8c7bd8-8824-4408-b8fc-49dc7f951a00
32位:
http://www.microsoft.com/zh-cn/download/details.aspx?id=5747
2、isapi_rewrite
http://www.helicontech.com/download-isapi_rewrite3.htm
但完全版有日期限制,如果不想掏钱,有大牛破解了,可以用下面这个:
http://download.csdn.net/detail/keke0307/3867086
3、urlrewriter.net
这个有源代码,可以自己编译。
机缘巧合之下,我用了方法一 和 二。因为开发机器是WIN7,装了IIS7,所以用微软的重写模块;而服务器是WIN2003,就用了isapi_rewrite。
下面就这两种方法分别做一点心得介绍。
事实上,这两种方法大同小异,IIS基本上不用怎么配置,没有网上说的那么玄妙,又是勾选,又是映射,又是权限之类,关键在于要写对正则表达式。
1、微软的 Microsoft URL 重写模块 2.0
安装好之后,就可以改写网站下的web.config了。
<configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> <httpRuntime/> </system.web> <system.webServer> <rewrite> <rules> <!-- 实现http://localhost/1024 ==> http://localhost/store/store.aspx?id=1024 --> <rule name="storecode"> <match url="^([1-9][0-9]*)/?$" ignoreCase="true"/> <action type="Rewrite" url="/store/store.aspx?id={R:1}"/> </rule> <!-- 实现http://localhost/1024/p=1&c=1 ==> http://localhost/store/store.aspx?id=1024&p=1&c=1 --> <rule name="storecode with param"> <match url="^([1-9][0-9]*)/([^/]+)/?$" ignoreCase="true"/> <action type="Rewrite" url="/store/store.aspx?id={R:1}&{R:2}"/> </rule> <!-- 下面这些据说是从Discuz论坛里导出来的,肯定是正确的,供学习借鉴 --> <!-- <rule name="已导入的规则 1"> <match url="^userinfo-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="userinfo.aspx?userid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 2"> <match url="^showforum-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="showforum.aspx?forumid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 3"> <match url="^showtopic-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="showtopic.aspx?topicid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 4"> <match url="^showforum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="showforum.aspx?forumid={R:1}&page= {R:2}" appendQueryString="false" /> </rule> <rule name="已导入的规则 5"> <match url="^showtopic-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="showtopic.aspx?topicid={R:1}&page= {R:2}" appendQueryString="false" /> </rule> <rule name="已导入的规则 6"> <match url="^archiver/showforum-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 7"> <match url="^archiver/showtopic-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 8"> <match url="^archiver/showtopic-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1} &page={R:2}" appendQueryString="false" /> </rule> <rule name="已导入的规则 9"> <match url="^archiver/showforum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1} &page={R:2}" appendQueryString="false" /> </rule> <rule name="已导入的规则 10"> <match url="^tools/rss-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="tools/rss.aspx?forumid={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 11"> <match url="^tools/spacerss-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=space" appendQueryString="false" /> </rule> <rule name="已导入的规则 12"> <match url="^tools/photorss-([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=photo" appendQueryString="false" /> </rule> <rule name="已导入的规则 13"> <match url="^space\/((\w|\s)+)((\/?))?$" ignoreCase="false" /> <action type="Rewrite" url="space/index.aspx?user={R:1}" appendQueryString="false" /> </rule> <rule name="已导入的规则 14"> <match url="^space\/((\w|\s|-)+)((\/?))?\?((.*)+)$" ignoreCase="false" /> <action type="Rewrite" url="space/index.asp
Given an NxM (N rows and M columns) integer matrix with non-negative values (0..MAX_INT inclusive). What is the maximum sum from going top left (0, 0) to bottom right (N-1, M-1) ? The condition is that when you're at point (p, q), you
can only move to either right (p, q+1) or down (p+1, q).
Expected time complexity O(N*M)
Expected space complexity O(N+M)
about space complexity, need elaborate on it.
package com.zhuyu_deng.test; public class Test { private static int findOptPath(int[][] a) { int d[][] = new int[a.length][a[0].length]; int m = a.length; int n = a[0].length; d[0][0] = a[0][0]; for (int i = 1; i < m; ++i) d[i][0] = d[i - 1][0] + a[i][0]; for (int j = 1; j < n; ++j) d[0][j] = d[0][j - 1] + a[0][j]; for (int i = 1; i < m; ++i) { for (int j = 1; j < n; ++j) { if (d[i-1][j] > d[i][j-1]) d[i][j] = a[i][j] + d[i-1][j]; else d[i][j] = a[i][j] + d[i][j-1]; } } for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) System.out.print(a[i][j] + " "); System.out.println(); } System.out.println(); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) System.out.print(d[i][j] + " "); System.out.println(); } return d[m - 1][n - 1]; } public static void main(String args[]) { // int[] a = {-2,11,-4,13,-5,-2}; int[][] b = { { 0, -2, -7, 0 }, { 9, 2, -6, 2 }, { -4, 1, -4, 1 }, { -1, 8, 0, -2 } }; int [][] matrix = { {2,3,4,1}, {1,1,3,9}, {2,2,3,1}, {2,2,3,1} }; System.out.println(findOptPath(matrix)); } }