Monthly Archives: November 2014

0-1 knapsack problem

key to solve this problem is this formula: f(n,m)=max{f(n-1,m), f(n-1,m-w[n])+v[n]}

public class KnapSack01 {
	
	public static void main(String[] args) {
		int[] w = {0, 2, 2, 6, 5, 4};
		int[] v = {0, 6, 3, 5, 4, 6};
		System.out.println(knapSack(w, v, 10));
	}
	
	public static int knapSack(int[] w, int[] v, int weight){
		int[][] f = new int[w.length][weight];
		for(int i = 1; i < w.length; i++ ){
			for(int j = 1; j < weight; j++){
				f[i][j] = Math.max(f[i-1][j], v[i] + f[i-1][(j - w[i]) < 0 ? 0 : (j - w[i])]);
			}
		}
		return f[w.length - 1][weight - 1];
	}

}

window.opener only works on server, but not on local machine

Today, I tried ckeditor function. But the window.opener.CKEDITOR.tools.callFunction always doesn’t work. I found out it works in IE, but not in chrome. It’s weird. After hours research, I put it in tomcat server, and started tomcat server, it works. So the conclustion is that window.operner only works in server, but not in local machine.

editor.html:

  1. <html>
  2. <head>
  3. <script src=”./ckeditor/ckeditor.js”></script>
  4. <script type=”text/javascript”>
  5. </script>
  6. </head>
  7. <body>
  8. <form method=”post”>
  9.     <textarea name=”content”>aaa</textarea>
  10. </form>
  11. <script language=”javascript” type=”text/javascript”>
  12.     CKEDITOR.replace( ‘content’, {
  13.         filebrowserBrowseUrl: ‘browser.html/browse.php’,
  14.         filebrowserUploadUrl: ‘browser.html/upload.php’,
  15.         filebrowserImageBrowseUrl: ‘browser.html?type=Images’,
  16.         filebrowserImageUploadUrl: ‘browser.html/upload.php?type=Images’
  17.     });
  18.     CKEDITOR.config.width = 850;
  19.     CKEDITOR.config.height = 300;
  20. </script>
  21. <input type=”button” onClick=”CKEDITOR.tools.callFunction(1, ‘abc.html’)” value=”setUrl”>
  22. </body>
  23. </html>

browser.html:

  1. <html>
  2. <head>
  3. <script type=”text/javascript”>
  4. function sendback(){
  5.          window.opener.CKEDITOR.tools.callFunction(1, ‘abc.html’);
  6. }
  7. </script>
  8. </head>
  9. <body>
  10. <form method=”post”>
  11.     <textarea name=”content”>aaa</textarea>
  12. </form>
  13. <input type=”button” value=”send back” onClick=”sendback();”/>
  14. </body>
  15. </html>