#include <iostream> #include <cstdio> #include <fstream> #define INF 100000000 #define ll long long using namespace std; int m,n,MX; int main() { int tt; ll dp; int MN_Rem,MXR; while(scanf("%d%d%d",&m,&n,&tt)!=EOF) { if(m>tt && n>tt) { cout<<0<<" "<<tt<<"\n"; continue; } MX =0; bool f =false; MN_Rem = INF; MXR = 0; for(int i=0;i<=10005;i++) { for(int j=0;j<=10005;j++) { dp
Category: DP
10313
#include <iostream> #include <string> #include <sstream> #define ll long long using namespace std; ll ways[400][400]; ll findways(int a,int b) { ll r=0; if(ways[a][b]!=-1) return ways[a][b]; if(a==0) return 1; else { r = 0; for(int i=b;i>=1;i–) if(a-i>=0) { r+=findways(a-i,i); //ways[a-i][i]=r; } ways[a][b]=r; } return r; } int main() { int a[3],b,c,n; string s; stringstream ss; for(int
11151
#include <stdio.h> #include <string.h> #include <string> #include <iostream> using namespace std; int table[1001][1001]; int main() { int n,len; string s; cin>>n; getchar(); while(n–) { getline(cin,s); if(s=="") { cout<<0<<"\n"; continue; } memset(table,0,sizeof(table)); len = s.size(); for(int i=0;i<=len;i++) { table[i][i]=1; } for(int length=2;length<=len;length++) { for(int i=0;i<=len-length+1;i++) { int end=i+length-1; if(end<0 || end>=len) continue; if(s[i]==s[end] && length==2) {
11137
#include <iostream> #define ll long long using namespace std; int arr[23]={0,1,8,27,64,125,216,343,512,729, 1000,1331,1728,2197,2744,3375,4096,4913,5832, 6859,8000,9261 }; ll ways[10005]; int main() { for(int j=0;j<10005;j++) ways[j]= 0; ways[0]=1; for(int i=1;i<=21;i++) { for(int j=arr[i];j<10005;j++) ways[j]+=ways[j-arr[i]]; } int n; while(cin>>n) { //cout<<calc(1,n)<<"\n"; cout<<ways[n]<<"\n"; } return 0; }
725
#include <iostream> #include <stdio.h> #include <map> #include <vector> using namespace std; map<int,int> m,n; vector<int> den[80]; vector<int> numer[80]; int main() { int cnt,org; for(int i=0;i<80;i++) { den[i].clear(); numer[i].clear(); } for(int i=1234;i<=98765;i++) { if(i%10==0 && i<10000) continue; org=i; m.clear(); if(i<10000) m[0]=1; while(org) { if(m[org%10]) break; m[org%10]=1; org/=10; } if(org) continue; cnt=1; for(int j=i*2;j<100000;j+=i) { cnt++; if(i<10000 &&
1213
Hint: Start from 1120 not to count same prime. #include <iostream> using namespace std; int dp[1121][15]; int main() { int n,k; int prme[189]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127, 131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349, 353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673, 677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809, 811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117, 1123, 1129}; for(int i=0;i<1121;i++) { for(int j=0;j<15;j++) { dp[i][j]=0; } } dp[0][0]=1; for(int i=0;i<187;i++) { for(int j=1120;j>=prme[i];j–) { for(int k=1;k<=14;k++) { dp[j][k]+=dp[j-prme[i]][k-1]; } } } /*for(int i=0;i<189;i++) for(int
11762
#include <iostream> #include <vector> #include <map> #include <stdio.h> using namespace std; int prime[1000001]; int primes[1000001]; double dp[1000001]; vector<int> vb; map<int,int> mp; int main() { int n,t; primes[0]=primes[1]=0; for(int i=2;i*i<1000001;i++) { if(prime[i]==0) { for(int j=i*i;j<1000001;j+=i) { prime[j]=1; primes[j]=i; } //primes[i]=i; } } prime[0]=prime[1]=0; for(int i=2;i<1000001;i++) { if(primes[i]==0) primes[i]=i; if(prime[i]) prime[i]=0; else prime[i]=1; prime[i]+=prime[i-1]; } dp[1]=0; for(int
11780
#include <iostream> #include <math.h> #include <map> #include <stdio.h> #include <string> #include <vector> using namespace std; map<int,int> mp; int fib[50]; double dp[1010]; int main() { fib[0]=0; fib[1]=1; fib[2]=2; mp[1]=1; mp[2]=2; for(int i=3;i<=20;i++) { fib[i]=fib[i-1]+fib[i-2]; mp[fib[i]]=i; } dp[1]=.4; for(int i=1;i<=1000;i++) { double p=i*1.6; double d=1000000; for(int j=1;j<=18;j++) { if(i-fib[j]>=0) { int a=mp[fib[j]]; double x; if((fib[a+1]+dp[i-fib[j]]-p)<0) { x=-1*(fib[a+1]+dp[i-fib[j]]-p);
991
Theory: For larger n, imagine choosing an arbitrary pair of people to shake hands. You’ve now divided the circle into two smaller circles (one of which may have 0 people in it). The number of ways you can arrange the rest of the people is the product of the answers for the two smaller circles.