Visitors hit counter dreamweaver
摘要: 下面是一种简答素数打表法:#include <iostream>#include <fstream>#include <math.h>using namespace std;#define N 100000 bool p[N]; //判断p[i]中的i是否为素数int pn[N]; //存储素数void prim_num(){ int i,j,n; for(i=1; i<=N; i++) p[i]=true; n=(int)sqrt(N); for(i=2; i<=n; i++) { for(j=i+i; j<=N; j+=i... 阅读全文
posted @ 2012-05-19 23:29 Jason Damon 阅读(2619) 评论(0) 推荐(0) 编辑
摘要: 记住这个公式就OK了。for i=1..N for v=w[i]..V f[v]=max{f[v],f[v-w[i]]+v[i]}.这样就转换成为了0/1背包问题是一样的,只不过第二个循环的顺序不一样而已。#include<iostream>#include <fstream>#define MIN(a,b) (a<b?a:b)#define INF 9999999#define MAXN 505#define MAX 10001using namespace std;int t,n,d,e,g;int v[MAXN],w[MAX],f[MAX];int main 阅读全文
posted @ 2012-05-19 21:45 Jason Damon 阅读(283) 评论(0) 推荐(0) 编辑