I found a Problem asking us to find the number of ways of representing the number as a sum of fibonnaci numbers. I read the editorial but unable to understand.Any one explain the approach for solving this problem ?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3857 |
| 2 | jiangly | 3810 |
| 3 | maroonrk | 3534 |
| 4 | tourist | 3528 |
| 5 | Kevin114514 | 3510 |
| 6 | turmax | 3411 |
| 7 | Um_nik | 3387 |
| 8 | Radewoosh | 3367 |
| 9 | heuristica | 3322 |
| 10 | strapple | 3317 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | maspy | 150 |
| 3 | Um_nik | 146 |
| 4 | Errichto | 139 |
| 5 | nik_exists | 138 |
| 6 | adamant | 136 |
| 7 | maroonrk | 134 |
| 8 | DNR | 133 |
| 9 | Dominater069 | 131 |
| 9 | AmShZ | 131 |
I found a Problem asking us to find the number of ways of representing the number as a sum of fibonnaci numbers. I read the editorial but unable to understand.Any one explain the approach for solving this problem ?
Suppose if a I have a array A={2,3,5}
Subsets of array={2},{3},{5},{2,3},2,5},{3,5},{2,3,5}
and the sum of all subsets =2+3+5+2+3+5+3+5+2+3+5=40.
Is there any standard algorithm to find sum of all subsets of array ?
I Searched on the internet and I found this recurrence f(n,k)=f(n-1,k-1)+f(n-k,k).
But unable to understand how it works?
I am trying to solve this problem on Tocoder.
In the problem they are given three colors red,green,black and the question is to find the postion with the best winning probability.
My doubt is that in order to find the best postion we need to check every configuration.Suppose if r=2,g=2,b=2 then there are (2+2+2)!/2!2!2! permutations.
But in editorial they are using just three loops. Any help will be highly appreciated.
I am learning Dinic algorithm from max-flow here.I am not able to understand the terms Level graph and blocking flow any one help me.
I am trying this Problem.The problem is about finding the max-flow in the graph.
I used Edmond-karp algorithm to solve this but I am getting wrong answer.It would be helpful if any one spotify the error.
#include<bits/stdc++.h>
using namespace std;
#define MX 1000000007
#define LL long long
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define len(x) x.length()
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORE(i,a,n) for(int i=a;i<=n;i++)
template<class T1> inline T1 maxi(T1 a,T1 b){return a>b?a:b;}
template<class T2> inline T2 mini(T2 a,T2 b){return a<b?a:b;}
int parent[101],G[101][101],rG[101][101];
bool bfs(int s,int t,int n)
{
bool vis[n+2];
memset(parent,0,sizeof parent);
memset(vis,0,sizeof vis);
queue<int>Q;
Q.push(s);
vis[s]=true;
while(!Q.empty())
{
int fnt=Q.front();
Q.pop();
for(int v=1;v<=n;v++)
{
if(!vis[v] and G[fnt][v]>0)
{
vis[v]=true;
parent[v]=fnt;
Q.push(v);
}
}
}
return vis[t];
}
int main()
{
int n,tst=1;
ri(n);
while(n)
{
int s,t,c,flow=0;
ri(s),ri(t),ri(c);
FORE(i,1,c)
{
int x,y,z;
ri(x),ri(y),ri(z);
G[x][y]+=z;
G[y][x]+=z;
}
while(bfs(s,t,n))
{
int path=9999999;
for(int v=t;v!=s;v=parent[v])
{
int u=parent[v];
path=mini(path,G[u][v]);
}
for(int v=t;v!=s;v=parent[v])
{
int u=parent[v];
G[u][v]-=path;
G[v][u]+=path;
}
flow+=path;
}
printf("Network %d\nThe bandwidth is %d.\n\n", tst++, flow);
ri(n);
}
}
I am learning tarjan's algorithm from here Tarjan algorithm.But I am not able to understand how we are finding strongly connected components using Stack and also Why there should be no backedge from a descendant of sub-tree rooted with V to its ancestor. In simple terms Strongly connected components forms a cycle.But without any backedge how will the cycle forms hence SCC.
Does the vertices with same low[v] values form the strongly connected components.
I am Learning Articulation points in Graph thoery which is an application of DFS.I wrote the code by taking reference from GeeksforGeeks [Atriculation Points].(http://www.geeksforgeeks.org/articulation-points-or-cut-vertices-in-a-graph/)
void dfs(int u)
{
static int time=0;
int child=0;
vis[u]=1;
dis_t[u]=low[u]=++time;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i];
if(!vis[v])
{
child++;
parent[v]=u;
dfs(v);
low[u]=min(low[u],low[v]);
if(parent[u]==-1 and child>1)
{
AP[u]=1;
}
if(parent[u]!=-1 and low[v]>=dis_t[u])
AP[u]=1;
}
else if(v!=parent[u])
low[u]=min(low[u],dis_t[v]);
}
}
I came across two conditions.
a vertex u is articulation point if one of the following two conditions is true.
1) u is root of DFS tree and it has at least two children.
2) u is not root of DFS tree and it has a child v such that no vertex in subtree rooted with v has a back edge to one of the ancestors (in DFS tree) of u.
First condition is clear,but I can,t understand the second one.Hoping some help:)
| Name |
|---|


