bzoj 1673: [Usaco2005 Dec]Scales 天平

版权声明:本文为博主原创文章,转载请联系博主。 https://blog.csdn.net/everlasting_20141622/article/details/77185214

题目链接


神奇的背包dfs


代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>

#define inf 999999999
#define ll long long

using namespace std;

int n,m;
ll a[1010];
ll sum[1010];
ll ans=0;

void dfs(int x,ll w){
	if(w>m)return;
	if(sum[x-1]+w<=m){
		ans=max(ans,sum[x-1]+w);
		return;
	}
	ans=max(ans,w);
	for(int i=1; i<x; i++){
		w+=a[i];
		dfs(i,w);
		w-=a[i];
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i];
	dfs(n+1,0);
	printf("%lld\n",ans);
	
	return 0;
}


展开阅读全文

Major Scales

09-03

In music, the range of audible frequencies is divided into octaves, where each octave spans frequencies within factor of 2 of one another. For example, the note called middle C corresponds to an audio frequency of 263 Hz. The octave below middle C spans the frequency range from 131.5 Hz to 263 Hz while the octave above middle C spans the range from 263 Hz to 526 Hz. nnAn octave contains 13 chromatic notes whose frequencies differ by a common ratio. The separation between two adjacent chromatic notes is called a half-step or semi-tone. Note that there are 12 semi-tones in an octave and therefore the frequency ratio represented by a semi-tone is 1.0593 (since 1.0593^12 = 2). A tone is two semi-tones.nWhile it might be convenient to use frequencies to describe musical notes, historical tradition demands that we name the notes of the chromatic scale, in order: C, C#, D, D#, E, F, F#, G, G#, A, A#, B, C, and so on, repeating the same names for each new octave.nnWestern music rarely uses all the notes in the chromatic scale. Instead, 8 of the 13 chromatic notes are commonly used a composition. The most common such set of 8 notes is the major scale. The 8 notes of a major scale, in order, are separated by: tone, tone, semi-tone, tone, tone, tone, semi-tone. A major scale can begin with any of the chromatic notes; this note defines the key of the scale. Coincidentally, in the key of C, the major scale consists of the notes: C, D, E, F, G, A, B, C. On the other hand, in the key of F, the major scale is: F, G, A, A#, C, D, E, F.nnThere are other scales, notably the minor scale, and music composed in a particular scale sometimes uses notes that are not within the scale, caled accidentals. We shall concern ourselves only with music composed in a major scale with no accidentals.nnYour job is to read a sequence of notes and to identify all the keys that the music might have been composed in. Your program need not have any musical ear: report a particular key if and only if all the notes come from the major scale in that key.nnnInputnnInput contains several test cases. Each test case consists of a single line of input, containing a sequence of chromatic notes separated by white space. No input line exceeds 1000 characters. The last line of input contains the word "END".nnnOutputnnFor each test case, output a line giving the possible keys, in the order given above.nnnSample InputnnC C D F E G A A F G BnA B C D E F G C#nC C D F E G A A F GnC C C C CnENDnnnSample OutputnnCnnC FnC C# D# F G G# A# 问答

没有更多推荐了,返回首页