上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 30 下一页
摘要: 1 //重量太大,用01背包容易超时 2 //数据只有20组。可以用dfs搜索最优解 3 #include 4 int a[25]; 5 int maxs,n,s; 6 void dfs(int,int); 7 int main() 8 { 9 int i; 10 while(~scanf("%d",&n)) 11 { 12 for(i=... 阅读全文
posted @ 2017-04-20 08:22 Posase 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #define inf 1<<30 4 using namespace std; 5 6 typedef struct 7 { 8 int l,w; 9 } cus; 10 cus a[5005],d[5005]; 11 int top; 12 13 int cmp(cus x,cus y) 14 { 15 i... 阅读全文
posted @ 2017-04-19 22:57 Posase 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1 //典型01背包。因为没置0还wa一次。。。。。。。 2 #include 3 #include 4 int v,d[1005]; 5 6 void bag(int c,int w) 7 { 8 for(int i=v; i>=c; --i) 9 if(d[i-c] + w > d[i]) 10 d[i] = d[i-c] ... 阅读全文
posted @ 2017-04-19 21:52 Posase 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 1 /* 2 s[i]表示前i个的和 3 d[i][j]表示第i个到第j个直接花费的最小代价 4 5 d[i][j] = min(d[i][k] + d[k][j])(k from i to j) 6 7 */ 8 #include 9 #define inf 1 45 const int N=210; 46 int n,t,stone[N],ans; 47 void co... 阅读全文
posted @ 2017-04-19 21:30 Posase 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 1 /* 2 1600年一月一日为星期6,所以算出ymd与1600-1-1差多少天对7取余即可 3 */ 4 #include 5 int a[10000]={0}; 6 int main() 7 { 8 int i,y,m,d,t = 0,ans; 9 for(i=1600; i2 && y%4==0 && y%100!=0) || y%400==0 && m... 阅读全文
posted @ 2017-04-18 09:09 Posase 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 1 /* 2 用一个数组记录递增子序列,保持s处为最长子序列的最后一个值 3 当输入x小于d[s]时,向前找x的位置覆盖即可 4 复杂度与经典算法同为n*n 5 加入二分查找,优化后为n*logn 6 */ 7 #include 8 #define inf 1=x && d[mid-1] x) 29 right = mid - 1; 30 ... 阅读全文
posted @ 2017-04-18 08:32 Posase 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1 /* 2 1、入手点为k( 6 #include 7 #include 8 #include 9 using namespace std; 10 typedef struct 11 { 12 int x,y; 13 } cus; 14 15 cus a[1005]; 16 int d[1005]; 17 18 int cmp(cus p1,cus p2) 19 { 2... 阅读全文
posted @ 2017-04-18 07:12 Posase 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1 //01背包 2 #include 3 #include 4 5 int d[30005],val; 6 7 void bag(int v,int w) 8 { 9 for(int i=val; i>=v; --i) 10 if(d[i] < d[i-v] + w) 11 d[i] = d[i-v] + w; 12 } 1... 阅读全文
posted @ 2017-04-15 21:19 Posase 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1 //简单的dp 2 #include 3 #define Max(a,b) ((a)>(b)?(a):(b)) 4 int d[25]; 5 int main() 6 { 7 int i,j,n,m,x,t,te; 8 scanf("%d%d",&n,&m); 9 for(i=1; i<=n; ++i) 10 { 11 for... 阅读全文
posted @ 2017-04-15 20:48 Posase 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1 /* 2 将字符串逆序,找出原字符串与该字符串的公共子序列,则其余部分为需要添加的字符 3 状态转移方程参考最长公共子字符串 4 http://www.cnblogs.com/qq188380780/p/6678471.html 5 */ 6 #include 7 #include 8 #define Max(a,b) ((a)>(b)?(a):(b)) ... 阅读全文
posted @ 2017-04-15 19:02 Posase 阅读(129) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 30 下一页