diff --git a/CP/Assignment4-Bit_Manipulation_Bit_Masks/Ankit Jain/484A.cpp b/CP/Assignment4-Bit_Manipulation_Bit_Masks/Ankit Jain/484A.cpp new file mode 100644 index 0000000..943a4d6 --- /dev/null +++ b/CP/Assignment4-Bit_Manipulation_Bit_Masks/Ankit Jain/484A.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +typedef long long ll; +ll monk(ll l, ll r) +{ +if ((l|l+1)> r) + return l; +else + return monk(l|l+1,r); +} +main() +{ + long long l,r; + int n; + cin>>n; + while(n--) + { + cin>>l>>r; + cout< +using namespace std; + +int main() +{ + string s; + cin>>s; + int m=0; + queueq ; + for(int i=0;i0 ; i--) + { + m+=(1 << i) ; + } + int n=0; + for(int i=(s.size()-1) ; i>=0 ; i--) + { + n+= (q.front()*(1< +using namespace std; +main() +{ +int n,l,r,x,i=0,flag=0,sum=0,a1,a2; +long a[15]; +cin>>n>>l>>r>>x; +for(i=0;i>a[i]; +sort(a,a+n); +for(int mask=0; mask<(1ll<=l && sum<=r) && ((a2-a1)>=x)) + flag++; +} +cout< +using namespace std; +main() +{ +long long x=0, a[100001]; +int n,q; +cin>>n>>q; +int prefix[32][n+1],l,r,p,i,j; +for(i=1;i<=n;i++) +cin>>a[i]; +for(i=0;i<31;i++) +{ + prefix[i][0]=0; + for(j=1;j<=n;j++) + prefix[i][j]=prefix[i][j-1]+bool(a[j]&(1<>l>>r; +x=0; +for(i=0;i<31;i++) +{ +p=prefix[i][r]-prefix[i][l-1]; +if (p +using namespace std; +double dp[2001][2001],p; +main() +{ +memset(dp,0,sizeof(dp)); +int n,i,j,t; +cin>>n>>p>>t; +for(int i=1;i<=n;i++) + for(int j=1;j<=t;j++) + dp[i][j]=p*dp[i-1][j-1]+dp[i][j-1]*(1-p)+p; +printf("%0.6f",dp[n][t]); +} \ No newline at end of file diff --git a/CP/Assignment7-DynamicProgramming/Ankit Jain/580D.cpp b/CP/Assignment7-DynamicProgramming/Ankit Jain/580D.cpp new file mode 100644 index 0000000..e0145e9 --- /dev/null +++ b/CP/Assignment7-DynamicProgramming/Ankit Jain/580D.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +#define maxx 20 +typedef long long ll; +ll dp[1<>n>>m>>k; +for(i=0;i>a[i]; +for(i=0;i>x>>y>>c; + x--; + y--; + benefit[x][y]=c; +} +cout< +using namespace std; +main() +{ +int n,sum[50]={0},i,j,d; +cin>>n; +for(i=1;i<50;i++) +sum[i]=i*(i+1)/2; +for(i=1;i<50;i++) +if (n<=sum[i]) +break; +d=sum[i]-n; +if (d==0) +{ +cout< +using namespace std; +main() +{ +int i, s[100001]={0},x,n,t,res; +cin>>t; +while(t--) +{ +cin>>n; +for(i=1;i<=n;i++) +{ +cin>>x; +if (x==-1) +s[i]=s[i-1]+1; +else +s[i]=s[i-1]; +} +res=1-s[1]+s[n]-s[1]; +for(i=2;i<=n;i++) +res=min(res,i-s[i]+s[n]-s[i]); +cout< +using namespace std; +int t,n,dp[100][100],a[100][100],i,j; +int fun(int i, int j) +{ +if (dp[i][j]!=-1) + return dp[i][j]; +if (i==(n-1)) + return dp[i][j]=a[i][j]; +return dp[i][j]= max(fun(i+1,j), fun(i+1,j+1)) + a[i][j]; +} +main() +{ +cin>>t; +while(t--) +{ +cin>>n; +memset(dp,-1,sizeof(dp)); +for(i=0;i>a[i][j]; +cout< + + +using namespace std; + + +bool vis[1001]; + +vectoradj[1001]; + +int g[1001]={0}; + +int bfs(int s) + +{ + + vis[s]=true; + + + queue q; + + + q.push(s); + + + while(!q.empty()) + + + { + + + int v=q.front(); + + + q.pop(); + + + for(int i=0;i>n; + + + for(i=1;i<=n;i++) + + + { + + + vis[i]=false; + + + } + + + for(i=1;i>x>>y; + + + adj[x].push_back(y); + + + adj[y].push_back(x); + + + } + + + cin>>q; + + for(i=1;i<=q;i++) + + { + + cin>>x; + + g[x]=1; + + } + + cout< + + +using namespace std; + + +int main() + +{ + int x,a,b,t,y; + + cin>>t; + + +while(t--) + + { + cin>>a>>b; + + for(int i=0;i>x>>y; + + cout< + +using namespace std; + +bool vis[100001]; + +vectoradj[100001]; + +int child[100001]={0},h=0; + +void dfs(int s) + +{ + + vis[s]=true; + + for(int i=0;i child[s]) + + h++; + + dfs(adj[s][i]); + + } + + } + +} + +int main() + +{ + + memset(vis,false,sizeof(vis)); + + int m,n,x,i,y; + + cin>>n>>m; + + for(i=0;i>x>>y; + + adj[x].push_back(y); + + adj[y].push_back(x); + + } + + for(i=1;i<=n;i++) + + { + + if (!vis[i]) + + { + + child[i]=adj[i].size(); + + dfs(i); + + } + + } + + cout< +using namespace std; + +int main() + +{ + + int N,d,sum=0; + + cin>>N; + + for(int i=0;i>d; + + sum+=d; + + } + +if (sum==2*(N-1)) + + cout<<"Yes"< + +using namespace std; + +bool vis[10001]; + +vectoradj[10001]; + +int n; + +int bfs(int s,vectoradj[]) + +{ + + +int l[n+1]; + +queue q; + +q.push(s); + +l[1]=0; + +vis[s]=true; + +while(!q.empty()) + +{ + +int t=q.front(); + +q.pop(); + +for(int i=0;i>p; + +while(p--) + +{ + + vectoradj[10001]; + + + cin>>n>>m; + + for(i=1;i<=n;i++) + + vis[i]=false; + + for(i=1;i<=m;i++) + + { + + cin>>x>>y; + + adj[x].push_back(y); + + adj[y].push_back(x); + + } + + cout< +using namespace std; +int a[1002][1002],c=0,n,m; +bool vis[1002][1002]; +void dfs(int i, int j) +{ + c++; + vis[i][j]=true; + if (j!=m-1) + { + if ((a[i][j+1]==1) && (vis[i][j+1]==false)) + { + dfs(i,j+1); + } + if (i!=0) + { + if ((a[i-1][j+1]==1) && (vis[i-1][j+1]==false)) + { + dfs(i-1,j+1); + } + } + } + if (i!=n-1) + { + if ((a[i+1][j]==1) && (vis[i+1][j]==false)) + { + dfs(i+1,j); + } + if (j!=m-1) + { + if ((a[i+1][j+1]==1) && (vis[i+1][j+1]==false)) + { + dfs(i+1,j+1); + } + } + } + if (j!=0) + { + if ((a[i][j-1]==1) && (vis[i][j-1]==false)) + { + dfs(i,j-1); + } + if (i!=n-1) + { + if ((a[i+1][j-1]==1) && (vis[i+1][j-1]==false)) + { + dfs(i+1,j-1); + } + } + } + if (i!=0) + { + if ((a[i-1][j]==1) && (vis[i-1][j]==false)) + { + dfs(i-1[j]); + } + if (j!=0) + { + if ((a[i-1][j-1]==1) && (vis[i-1][j-1]==false)) + { + dfs(i-1,j-1); + } + } + } +} +int main() +{ int max=0,count=0,i,t,j; + cin>>t; + while(t--) + { + count=0; + max=0; + cin>>n>>m; + for(i=0;i<=n;i++) + for(j=0;j<=m;j++) + { + a[i][j]=0; + vis[i][j]=false; + } + for(i=0;i>a[i][j]; + for(i=0;imax) + max=c; + c=0; + } + cout<