#include <iostream> #include <cstdio> #include <cstdlib> #include <iomanip> #include <fstream> #define INF 10000000 using namespace std; int availabe_coin[6]; int min_ways[1005]; int visit[6]; int coins[6]={5,10,20,50,100,200}; int cost; int cmp; void dp(int tcost,int index,int noOfsteps) { int tmp,v; if(tcost>=cost) { int d = tcost-cost; if(d>1003) return; if(min_ways[d]!=INF) { tmp = noOfsteps+min_ways[tcost-cost]; if(tmp<cmp) { cmp = tmp; return;
Month: March 2015
10912
#include <iostream> using namespace std; int L,S; int dp[27][352][27];//[length][total][last element] int res_dp[27][352]; int main() { int kase=1; for(int i=1;i<27;i++) { dp[1][i][i]=1; } for(int i=2;i<=26;i++)//length of the string for(int j=1;j<=351;j++)//sum of all the value for(int k=1;k<=26;k++)//max last ending value for(int ll=1;ll<k;ll++) { dp[i][j][k]+=dp[i-1][j-k][ll]; } for(int i=1;i<=26;i++) for(int j=1;j<=351;j++) for(int k=1;k<=26;k++) res_dp[i][j]+=dp[i][j][k]; while(cin>>L) { cin>>S; if(L+S==0) break;
116
#include <iostream> #include <cstdio> #define MX 100000000 using namespace std; int r,c; int input[11][101]; int dp[11][101]; int next_row[11][101]; int main() { int tmp,temp_position,row; while(scanf("%d%d",&r,&c)==2) { for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin>>input[i][j]; for(int i=0;i<r;i++) dp[i][c-1]=input[i][c-1]; for(int i=c-2;i>=0;i–) { for(int j=0;j<r;j++) { tmp=MX; for(int k=-1;k<=1;k++) { temp_position = (j+k+r)%r; if(tmp>dp[temp_position][i+1] || (tmp==dp[temp_position][i+1] && temp_position<next_row[j][i])) { next_row[j][i]=temp_position; tmp =
196
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <string> #include <cmath> #include <sstream> using namespace std; string str[1000][18279]; int val[1000][18279]; bool isDone[1000][18279]; int C,R; int solve(int a,int b) { if(isDone[a][b]) return val[a][b]; string tmpstr; for(int i=0;i<str[a][b].size();i++) { if(str[a][b][i]=='=' || str[a][b][i]=='+') { str[a][b][i]=' '; } } stringstream ss; ss<<str[a][b]; int sum = 0;
872
#include <iostream> #include <string> #include <sstream> #include <fstream> #include <queue> #include <algorithm> #include <cstring> #include <set> using namespace std; int noOfelement; int mp[26]; string str,str1,str2; string output[2000]; int kk; bool gr[27][27]; stringstream ss; int elements[26]; set<string> SET; //ofstream out; bool check(int elemnt,bool visit[]) { for(int i=0;i<26;i++) { if(gr[i][elemnt] && mp[i]!=-1 && visit[mp[i]]==0) return 0; }
124
#include <iostream> #include <string> #include <sstream> #include <fstream> #include <queue> #include <algorithm> #include <cstring> #include <set> using namespace std; int noOfelement; int mp[26]; string str,str1,str2; string output[2000]; int kk; bool gr[27][27]; stringstream ss; int elements[26]; set<string> SET; //ofstream out; bool check(int elemnt,bool visit[]) { for(int i=0;i<26;i++) { if(gr[i][elemnt] && mp[i]!=-1 && visit[mp[i]]==0) return 0; }
452
#include <iostream> #include <sstream> #include <string> #include <queue> #include <cstdio> #define INF 10000000 using namespace std; bool gr[26][26]; int daysreq[26],indegree[26]; int accumulated_days[26]; int t; int bfs(queue<int> q) { while(!q.empty()) { int a = q.front();q.pop(); for(int i=0;i<26;i++) { if(gr[a][i]) { accumulated_days[i]=max(accumulated_days[i],accumulated_days[a]+daysreq[i]); if(–indegree[i]==0) q.push(i); } } } int MX = 0; for(int i=0;i<26;i++) { MX = max(accumulated_days[i],MX);
10937
#include <cstdio> #include <queue> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #define INF 10000 using namespace std; int location,target; vector<vector<int> > dp; int h,w; int graph[200][200]; string str[60]; struct POINT{ int x,y; }; POINT pp[3030]; POINT src,tr; int k; int dirx[4]={1,0,0,-1}; int diry[4]={0,1,-1,0}; int bfs(int s,int t) { int tmpy,tmpx; queue<int> q;
10349
This is a bipartite matching problem. This can be solved using Ford fulkerson algorithm for Max flow problem. #include <iostream> #include <limits.h> #include <string.h> #include <queue> using namespace std; int gr[500][500]; int rgr[500][500]; string str[50]; int h,w; int numOfantena; int parent[500]; bool visited[500]; int src,targt; bool bfs(int s, int t) { memset(visited, 0, sizeof(visited)); queue
10076
Problem description error: ∆T = ⌈β2(h2 − h1)⌉ + γ, if h1 < h2 , here if we use γ as problem description,we get WA from online judge,so use δ here to get accepted. #include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <cmath> #define INF 100000000 using namespace std; int M,N; int gr[20][20]; int dirx[4]={1,0,0,-1};