随笔分类 - 题
摘要:1 //并查集+01背包 2 //用并查集把几件物品合为一件 3 #include 4 using namespace std; 5 const int maxn=10005; 6 const int maxv=10005; 7 int n,m,v_tot,tot,v[maxn],w[maxn],dp[maxv]; 8 struct node{ 9 int fa,c...
阅读全文
摘要:1 //依赖关系最多2种 可以用分组背包水过 2 #include 3 using namespace std; 4 #define w first 5 #define v second 6 const int maxv=32005; 7 const int maxn=65; 8 int n,m,k,tot,f[maxv],ID[maxn]; 9 vector >d[m...
阅读全文
摘要:1 //分组背包 2 #include 3 using namespace std; 4 int n,m,k,tot,f[1005];//tot-组数 5 vector >d[105]; 6 int main() 7 { 8 scanf("%d%d",&m,&n); 9 for(int i=1,x,y,z;i=0;--j)//注意三层循环顺序 12 ...
阅读全文
摘要:1 //二维费用01背包 2 #include 3 using namespace std; 4 const int maxn=105; 5 const int maxv1=1005; 6 const int maxv2=1005; 7 int v1[maxn],v2[maxn],w[maxn],n,v1_tot,v2_tot,f[maxv1][maxv2]; 8 int mai...
阅读全文
摘要:1 //二维费用背包 2 #include 3 using namespace std; 4 const int maxn=55; 5 const int maxv1=405; 6 const int maxv2=405; 7 int v1[maxn],v2[maxn],w[maxn],n,v1_tot,v2_tot,f[maxv1][maxv2]; 8 int main() ...
阅读全文
摘要:1 //01背包 价值等于重要度乘体积 2 #include 3 using namespace std; 4 const int maxv=30005; 5 const int maxn=10005; 6 int n,m,v[maxn],w[maxn],f[maxv]; 7 int main() 8 { 9 scanf("%d%d",&m,&n); 10 f...
阅读全文
摘要:1 //完全背包 2 #include 3 using namespace std; 4 const int maxv=100005; 5 const int maxn=10005; 6 int n,m,v[maxn],w[maxn],f[maxv]; 7 int main() 8 { 9 scanf("%d%d",&m,&n); 10 for(int i=1...
阅读全文
摘要:1 //求方案数 定义状态f[i][j] 用前i件物品恰好放够体积为j的背包 方案数 2 #include 3 using namespace std; 4 const int maxm=10005; 5 const int maxn=105; 6 int n,m,v[maxn],f[maxn][maxm]; 7 int main() 8 { 9 scanf("%d%...
阅读全文
摘要:1 //01背包 2 #include 3 using namespace std; 4 const int maxv=1005; 5 const int maxn=105; 6 int n,v_tot,v[maxn],w[maxn],f[maxv],sumv,bound; 7 int main() 8 { 9 scanf("%d%d",&v_tot,&n); 10 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 vector q; 4 int n,opt,x; 5 int main() 6 { 7 scanf("%d",&n); 8 while(n--) 9 { 10 scanf("%d%d",&opt,&x); 11 switch(opt) 12 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=1005; 4 const int maxm=3005; 5 struct edge{int to,nex;}e[maxm]; 6 int head[maxn],tot; 7 int deep[maxn],f[maxn][30]; 8 int T,n,m,q; 9 inline...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 const int INF=0x3f3f3f3f; 5 inline void read(int &tmp) 6 { 7 int x=1;char c=getchar(); 8 for(tmp=0;!isdigit(c);c=getchar()) ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=505; 4 const int maxm=100005; 5 int n,k,sum,tot; 6 struct node{ 7 int cnt,fa; 8 }f[maxn]; 9 int find(int x){return f[x].fa==x?x:f[x].fa...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5050; 4 const int maxm=5000005; 5 int n,m,k,ans; 6 double Max; 7 int monkey[maxn]; 8 typedef pair P; 9 P point[maxn]; 10 #define Dis(x,y) (...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=505; 4 const int maxm=100005; 5 int n,k,Max,tot; 6 struct node{ 7 int cnt,fa; 8 }f[maxn]; 9 int find(int x){return f[x].fa==x?x:f[x].fa...
阅读全文
摘要:1 #include 2 using namespace std; 3 typedef long long ll; 4 ll m,n,x,y,l,t,k,d; 5 void exgcd(ll a,ll b,ll &x,ll &y) {if(!b) {x=1;y=0;d=a;return;}exgcd(b,a%b,y,x);y-=x*(a/b);} 6 int main() 7 { ...
阅读全文
摘要:1 /* 2 性质:一个树里,删掉n条边一定出现n+1个连通块 3 若删去无向连通图中所有权值大于m的边,原图被分割成k个连通块,则最小生成树也被分割成k个联通块 4 */ 5 #include 6 using namespace std; 7 const int maxn=505; 8 const int maxm=250005; 9 struct node{int cn...
阅读全文
摘要:1 /* 2 用kuskal会被卡 3 一边prim一边算两点间距离(边权) 4 否则会MLE 5 另:不开long long见祖宗 6 */ 7 #include 8 using namespace std; 9 const int maxn=5005; 10 const int INF=0x3f3f3f3f; 11 typedef pair P; 12 priority...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=10005; 4 const int maxm=100005; 5 const int INF=0x3f3f3f3f; 6 inline void read(int &tmp) 7 { 8 int x=1;char c=getchar(); 9 for(tmp...
阅读全文
摘要:1 #include 2 using namespace std; 3 inline void read(int &tmp) 4 { 5 int x=1;char c=getchar(); 6 for(tmp=0;!isdigit(c);c=getchar()) if(c=='-') x=-1; 7 for(;isdigit(c);tmp=tmp*10+c-...
阅读全文

浙公网安备 33010602011771号