上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 42 下一页
bug:忘了给dp[0]赋值为1了#include<stdio.h>#include<string.h>bool dp[20000000];int h[22];int main(){ int n,b,i,j,sum=0; scanf("%d%d",&n,&b); for(i=1;i<=n;i++) { scanf("%d",&h[i]); sum+=h[i]; } memset(dp,0,sizeof(dp));dp[0]=1; for(i=1;i<=n;i++) { for(j=sum;j&g Read More
posted @ 2011-11-17 04:32 Because Of You Views(207) Comments(0) Diggs(0) Edit
背包入门题。。View Code 1 #include<stdio.h> 2 #include<string.h> 3 int dp[12885]; 4 int max(int a,int b) 5 { 6 return a>b?a:b; 7 } 8 int main() 9 {10 int n,m,i,j,w,v;11 while(scanf("%d%d",&n,&m)!=EOF)12 {13 memset(dp,0,sizeof(dp));14 for(i=1;i<=n;i++)15 {16 ... Read More
posted @ 2011-11-17 04:19 Because Of You Views(220) Comments(0) Diggs(0) Edit
#include<stdio.h>#include<string.h>int a[510],b[510];int dp[510];int main(){ int t,m,n,i,j; scanf("%d",&t); while(t--) { scanf("%d",&m); for(i=1;i<=m;i++) scanf("%d",&a[i]); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d&quo Read More
posted @ 2011-11-17 04:10 Because Of You Views(1081) Comments(0) Diggs(0) Edit
改天把2-sat刷完了再一起总结吧,先放这儿#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int MAX =20010;vector<int> edge[MAX];int st[MAX];int dfn[MAX],low[MAX];int top,btype,tdfn;int belong[MAX];bool ins[MAX];void dfs(int s){ int i,t; dfn[s] Read More
posted @ 2011-11-14 21:25 Because Of You Views(297) Comments(0) Diggs(0) Edit
2-sat入门题,建图后直接模板就好了开始的时候竟然连了双向的边,晕。。。。。#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int MAX = 10010;vector<int> edge[MAX];int st[MAX];int dfn[MAX],low[MAX];int top,btype,tdfn;//btype:连通块的个数int belong[MAX];//点属于哪个连通块bool Read More
posted @ 2011-11-12 23:48 Because Of You Views(251) Comments(0) Diggs(0) Edit
思想的话看这里http://www.cnblogs.com/lotus3x/archive/2009/03/21/1418480.html二分法:/*the length of the channel is the horizontal distance between the two villages. The cost of the channel is the height of the lifter. 最优比率生成树poj 2728目标:min{∑costi/∑leni}逼近的思想,∑costi/∑leni<=x,即 ∑(costi-x*leni)<=0 是一个单调递减函数 Read More
posted @ 2011-11-12 21:21 Because Of You Views(890) Comments(1) Diggs(0) Edit
一圈的点从0到n-1顺次围起来,题目中给出m条links,要求你把这些link对应的点连起来,问是否存在一种可能使得连完后不存在相交的两条线另外,连线有两种连法,内部相连与外部相连,而且题目保证Every point will have at most one link.很明显的two-sat(虽然做之前已经知道是two-sat了,囧)把每条边看成图中的一个点,如果两条边的区间存在相交,则两条边必然是一内一外才能保证不相交。假如有m条边要连接,则实际可能被连的边有2*m条建图的时候,假设1到m都是在内部的边,m+1到2*m对应外部的边,如果i,j之间区间存在交集,即矛盾了,则必须把 i ,j+ Read More
posted @ 2011-11-11 19:47 Because Of You Views(213) Comments(0) Diggs(0) Edit
给定一棵树,每个节点有一个权值。任意去掉一条边会形成两颗子树,每颗子树有一个权值和,求二者相差的最小值。dfs的时候求出当前节点和其子树的节点的总权值w,并和sum-w相减,和ans比较即可View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<vector> 4 using namespace std; 5 vector<int> mm[100010]; 6 int W[100010]; 7 bool vis[100010]; 8 __int64 ans,sum; 9 __in Read More
posted @ 2011-11-11 13:24 Because Of You Views(374) Comments(0) Diggs(0) Edit
a.toPlainString()可以去掉后面的0;View Code 1 import java.math.*; 2 import java.io.*; 3 import java.util.*; 4 public class Main{ 5 public static void main(String args[]) 6 { 7 Scanner cin=new Scanner(System.in); 8 BigDecimal a,b; 9 // BigInteger zero = new BigInteger("0");10 ... Read More
posted @ 2011-11-11 12:49 Because Of You Views(480) Comments(0) Diggs(0) Edit
View Code 1 import java.math.*; 2 import java.io.*; 3 import java.util.*; 4 public class Main{ 5 public static void main(String args[]) 6 { 7 Scanner cin=new Scanner(System.in); 8 int i,j,t; 9 BigInteger f[]=new BigInteger[1001];10 f[1]=BigInteger.valueOf(1);... Read More
posted @ 2011-11-11 12:37 Because Of You Views(216) Comments(0) Diggs(0) Edit
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 42 下一页