#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int n,k[110],m[110][110];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>k[i];
int ans=INF;
for(int i=0;i<n;i++)
{
int temp=k[i]*15;;
for(int j=0;j<k[i];j++)
{
cin>>m[i][j];
temp+=m[i][j]*5;
}
ans=min(ans,temp);
}
cout<<ans<<endl;
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char sa[1100],sb[1100];
int color1[30],color2[30];
int main()
{
cin>>sa>>sb;
int n=strlen(sa),m=strlen(sb);
for(int i=0;i<n;i++)
{
color1[sa[i]-'a']++;
}
for(int i=0;i<m;i++)
{
color2[sb[i]-'a']++;
}
int ans=0,flag=true;
for(int i=0;i<30;i++)
{
ans+=min(color1[i],color2[i]);
if(color2[i]&&color1[i]==0)
flag=false;
}
if(ans==0||flag==false) puts("-1");
else cout<<ans<<endl;
return 0;
}
可能组合太少,直接暴力枚举
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
int a,b;
typedef pair<int,int> pII;
set<pII> sa,sb;
int main()
{
cin>>a>>b;
for(int i=0;i<1000;i++)
{
if(i*i>a*a) break;
int temp=a*a-i*i;
int j=(int)(sqrt(temp));
if(j*j==temp)
{
if(i==0||j==0) continue;
sa.insert(make_pair(i,j));
sa.insert(make_pair(i,-j));
sa.insert(make_pair(-i,j));
sa.insert(make_pair(-i,-j));
}
}
for(int i=0;i<1000;i++)
{
if(i*i>b*b) break;
int temp=b*b-i*i;
int j=(int)(sqrt(temp));
if(j*j==temp)
{
if(i==0||j==0) continue;
sb.insert(make_pair(i,j));
sb.insert(make_pair(i,-j));
sb.insert(make_pair(-i,j));
sb.insert(make_pair(-i,-j));
}
}
set<pII>::iterator ita,itb;
for(ita=sa.begin();ita!=sa.end();ita++)
{
int xa,xb,ya,yb;
xa=ita->first,ya=ita->second;
for(itb=sb.begin();itb!=sb.end();itb++)
{
xb=itb->first,yb=itb->second;
if(xa*xb+ya*yb==0)
{
if(xa==0||xb==0||ya==0||yb==0||xa==xb||ya==yb) continue;
else
{
puts("YES");
cout<<0<<" "<<0<<endl;
cout<<xa<<" "<<ya<<endl;
cout<<xb<<" "<<yb<<endl;
return 0;
}
}
}
}
puts("NO");
return 0;
}
递推,经过前面一个点两次才能走到下一个点
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const long long int MOD=1e9+7;
long long int dp[1100];
int n,p[1100];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>p[i];
for(int i=2;i<=n+1;i++)
{
dp[i]=(2*dp[i-1]-dp[p[i-1]]+2+MOD)%MOD;
}
cout<<dp[n+1]%MOD<<endl;
return 0;
}