摘要: python中用来实现协程的两种方法提高程序的效率。**第一种**利用greenlat 实现 代码如下:需提前安装greenlat(pip install greenlat)from greenlat import greenlat 结果: 第二种:利用asyncio 结果如上图。协程的意义:能让线 阅读全文
posted @ 2021-04-03 15:40 zw100 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 例如 90=2*3^2*5; N=p1^r1*p2^r2*p3^r3.........pn^rn(pi是质数且p1<p2<p3<.....<pn). 代码实现 #include<cstdio> #include<iostream> #include<algorithm> #include<map> 阅读全文
posted @ 2019-08-12 20:51 zw100 阅读(365) 评论(0) 推荐(0) 编辑
摘要: 代码如下; #include<iostream>#include<vector>#include<queue>#include<cstring>using namespace std;const int maxn = 1000;int in[maxn];vector<int>V[maxn]; int 阅读全文
posted @ 2019-08-09 19:29 zw100 阅读(89) 评论(0) 推荐(0) 编辑
摘要: int pow(int a,int b,int c)//a为底数,b为指数,c模数。 { int ans=1; a=a%c; while(b>0) { if(b&1) { ans=(ans*a)%c; } a=(a*a)%c; b=b/2; } return ans; } 阅读全文
posted @ 2019-08-01 11:00 zw100 阅读(69) 评论(0) 推荐(0) 编辑
摘要: 代码 ; int pow(int a,int b)//b为幂。 { int ans=1; while(b>0) { if(b%2!=0){ans*=a} a=a*a; b=b/2; } } 阅读全文
posted @ 2019-08-01 10:40 zw100 阅读(62) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<cstdio>#include<algorithm> using namespace std;const int maxn = 1e4+100;int dp[maxn];int p[maxn],n,m; int main(){ while(cin 阅读全文
posted @ 2019-08-01 09:46 zw100 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 普通代码实现: for(int i=0;i<n;i++){ for(int j=0;j<=W;j++){ if(j<w[i]) dp[i+1][j]=dp[i][j]; else dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+p[i]); } } cout<< dp 阅读全文
posted @ 2019-07-31 17:53 zw100 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1. 要求背包必须装满且求最大值 把记忆数组初始化dp[0]=0, 其余为负无穷。 2, 要求背包必须装满且求最小值 把记忆数组初始化dp[0]=0, 其余为正无穷。 阅读全文
posted @ 2019-07-31 17:04 zw100 阅读(380) 评论(0) 推荐(0) 编辑
摘要: 核心代码; 定义 dp[i][j] 是从前不i-1个物品中,选出来总重量不超过j的物品时,总价值的最大值 显然 dp[i][j]=0, 因为你没物品可以取的时候,背包的价值为零。 dp[0][j]=0; for(int i=0;i<n;i++){ for(int j=0;j<w;j++){ if(j 阅读全文
posted @ 2019-07-31 10:11 zw100 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 代码如下: #include<iostream> #include<cmath> #include<cstring> using namespace std; int n,m; int a[110][110],dp[110][110]; int dir[4][2]={0,1,0,-1,1,0,-1, 阅读全文
posted @ 2019-07-30 20:45 zw100 阅读(128) 评论(0) 推荐(0) 编辑